def __init__( self, schema: str, table: str, role: str, grant: Union[PGGrantTableChoice, str], columns: Optional[List[str]] = None, with_grant_option=False, ): self.schema: str = coerce_to_unquoted(schema) self.table: str = coerce_to_unquoted(table) self.columns: List[str] = sorted(columns) if columns else [] self.role: str = coerce_to_unquoted(role) self.grant: PGGrantTableChoice = PGGrantTableChoice(grant) self.with_grant_option: bool = with_grant_option self.signature = self.identity if PGGrantTableChoice(self.grant) in {C.SELECT, C.INSERT, C.UPDATE, C.REFERENCES}: if len(self.columns) == 0: raise BadInputException( f"When grant type is {self.grant} a value must be provided for columns" ) else: if self.columns: raise BadInputException( f"When grant type is {self.grant} a value must not be provided for columns" )
def __init__(self, schema: str, signature: str): self.schema: str = coerce_to_unquoted(normalize_whitespace(schema)) self.signature: str = coerce_to_unquoted( normalize_whitespace(signature)) # Include schema in definition since extensions can only exist once per # database and we want to detect schema changes and emit alter schema self.definition: str = f"{self.__class__.__name__}: {self.schema} {self.signature}"
def __init__( self, schema: str, table: str, columns: List[str], role: str, grant: Union[Grant, str], with_grant_option=False, ): self.schema: str = coerce_to_unquoted(schema) self.table: str = coerce_to_unquoted(table) self.columns: List[str] = sorted(columns) self.role: str = coerce_to_unquoted(role) self.grant: Grant = Grant(grant) self.with_grant_option: bool = with_grant_option
def __init__(self, schema: str, signature: str, definition: str, on_entity: str): super().__init__(schema=schema, signature=signature, definition=definition) if "." not in on_entity: on_entity = "public." + on_entity # Guarenteed to have a schema self.on_entity = coerce_to_unquoted(on_entity)
def __init__(self, schema: str, signature: str, definition: str): self.schema: str = coerce_to_unquoted(normalize_whitespace(schema)) self.signature: str = coerce_to_unquoted(normalize_whitespace(signature)) self.definition: str = escape_colon_for_sql(strip_terminating_semicolon(definition))
def test_coerce_to_unquoted() -> None: assert coerce_to_unquoted('"public"') == "public" assert coerce_to_unquoted("public") == "public" assert coerce_to_unquoted("public.table") == "public.table" assert coerce_to_unquoted('"public".table') == "public.table"