def add_privs(self): """Generate SQL statements to grant privileges on new column :return: list of SQL statements """ return [add_grant(self._table, priv, self.name) for priv in self.privileges]
def add_privs(self): """Generate SQL statements to grant privileges on new column :return: list of SQL statements """ stmts = [] if hasattr(self, 'privileges'): for priv in self.privileges: stmts.append(add_grant(self._table, priv, self.name)) return stmts
def create(self): """Return SQL statements to CREATE the table :return: SQL statements """ # TODO This was *maybe* in place to guard double creations caused by # the functions. Leaving it here, to be dropped once I'm reasonably # certain we get called only once, when expected. assert not hasattr(self, 'created') stmts = [] cols = [] colprivs = [] for col in self.columns: if not (hasattr(col, 'inherited') and col.inherited): cols.append(" " + col.add()[0]) colprivs.append(col.add_privs()) unlogged = '' if hasattr(self, 'unlogged') and self.unlogged: unlogged = 'UNLOGGED ' inhclause = '' if hasattr(self, 'inherits'): inhclause = " INHERITS (%s)" % ", ".join(t for t in self.inherits) opts = '' if hasattr(self, 'options'): opts = " WITH (%s)" % ', '.join(self.options) tblspc = '' if hasattr(self, 'tablespace'): tblspc = " TABLESPACE %s" % self.tablespace stmts.append("CREATE %sTABLE %s (\n%s)%s%s%s" % (unlogged, self.qualname(), ",\n".join(cols), inhclause, opts, tblspc)) if self.owner is not None: stmts.append(self.alter_owner()) for priv in self.privileges: stmts.append(add_grant(self, priv)) if colprivs: stmts.append(colprivs) if self.description is not None: stmts.append(self.comment()) for col in self.columns: if col.description is not None: stmts.append(col.comment()) if hasattr(self, '_owned_seqs'): for dep in self._owned_seqs: stmts.append(dep.add_owner()) self.created = True return stmts
def create(self): """Return SQL statements to CREATE the table :return: SQL statements """ stmts = [] if hasattr(self, 'created'): return stmts cols = [] colprivs = [] for col in self.columns: if not (hasattr(col, 'inherited') and col.inherited): cols.append(" " + col.add()[0]) colprivs.append(col.add_privs()) unlogged = '' if hasattr(self, 'unlogged') and self.unlogged: unlogged = 'UNLOGGED ' inhclause = '' if hasattr(self, 'inherits'): inhclause = " INHERITS (%s)" % ", ".join(t for t in self.inherits) opts = '' if hasattr(self, 'options'): opts = " WITH (%s)" % ', '.join(self.options) tblspc = '' if hasattr(self, 'tablespace'): tblspc = " TABLESPACE %s" % self.tablespace stmts.append("CREATE %sTABLE %s (\n%s)%s%s%s" % ( unlogged, self.qualname(), ",\n".join(cols), inhclause, opts, tblspc)) if hasattr(self, 'owner'): stmts.append(self.alter_owner()) if hasattr(self, 'privileges'): for priv in self.privileges: stmts.append(add_grant(self, priv)) if colprivs: stmts.append(colprivs) if hasattr(self, 'description'): stmts.append(self.comment()) for col in self.columns: if hasattr(col, 'description'): stmts.append(col.comment()) self.created = True return stmts
def create(self): """Return SQL statements to CREATE the table :return: SQL statements """ stmts = [] if hasattr(self, 'created'): return stmts cols = [] colprivs = [] for col in self.columns: if not (hasattr(col, 'inherited') and col.inherited): cols.append(" " + col.add()[0]) colprivs.append(col.add_privs()) unlogged = '' if hasattr(self, 'unlogged') and self.unlogged: unlogged = 'UNLOGGED ' inhclause = '' if hasattr(self, 'inherits'): inhclause = " INHERITS (%s)" % ", ".join(t for t in self.inherits) opts = '' if hasattr(self, 'options'): opts = " WITH (%s)" % ', '.join(self.options) tblspc = '' if hasattr(self, 'tablespace'): tblspc = " TABLESPACE %s" % self.tablespace stmts.append("CREATE %sTABLE %s (\n%s)%s%s%s" % (unlogged, self.qualname(), ",\n".join(cols), inhclause, opts, tblspc)) if self.owner is not None: stmts.append(self.alter_owner()) for priv in self.privileges: stmts.append(add_grant(self, priv)) if colprivs: stmts.append(colprivs) if self.description is not None: stmts.append(self.comment()) for col in self.columns: if col.description is not None: stmts.append(col.comment()) self.created = True return stmts
def grant(obj, *args, **kwargs): stmts = func(obj, *args, **kwargs) if hasattr(obj, 'privileges'): for priv in obj.privileges: stmts.append(add_grant(obj, priv)) return stmts
def grant(obj, *args, **kwargs): stmts = func(obj, *args, **kwargs) for priv in obj.privileges: stmts.append(add_grant(obj, priv)) return stmts