def create_constr_trigger(self, table_name, constraint, proc_name): cmds = [] cname = constraint.raw_constraint_name() ins_trigger_name = common.edgedb_name_to_pg_name(cname + '_instrigger') ins_trigger = dbops.Trigger(name=ins_trigger_name, table_name=table_name, events=('insert', ), procedure=proc_name, is_constraint=True, inherit=True) cr_ins_trigger = dbops.CreateTrigger(ins_trigger) cmds.append(cr_ins_trigger) disable_ins_trigger = dbops.DisableTrigger(ins_trigger, self_only=True) cmds.append(disable_ins_trigger) upd_trigger_name = common.edgedb_name_to_pg_name(cname + '_updtrigger') condition = constraint.get_trigger_condition() upd_trigger = dbops.Trigger(name=upd_trigger_name, table_name=table_name, events=('update', ), procedure=proc_name, condition=condition, is_constraint=True, inherit=True) cr_upd_trigger = dbops.CreateTrigger(upd_trigger) cmds.append(cr_upd_trigger) disable_upd_trigger = dbops.DisableTrigger(upd_trigger, self_only=True) cmds.append(disable_upd_trigger) return cmds
def rename_constr_trigger(self, table_name): constraint = self._constraint new_constr = self._new_constraint cname = constraint.raw_constraint_name() ncname = new_constr.raw_constraint_name() ins_trigger_name = common.edgedb_name_to_pg_name(cname + '_instrigger') new_ins_trg_name = common.edgedb_name_to_pg_name( ncname + '_instrigger') ins_trigger = dbops.Trigger( name=ins_trigger_name, table_name=table_name, events=('insert', ), procedure='null', is_constraint=True, inherit=True) rn_ins_trigger = dbops.AlterTriggerRenameTo( ins_trigger, new_name=new_ins_trg_name) upd_trigger_name = common.edgedb_name_to_pg_name(cname + '_updtrigger') new_upd_trg_name = common.edgedb_name_to_pg_name( ncname + '_updtrigger') upd_trigger = dbops.Trigger( name=upd_trigger_name, table_name=table_name, events=('update', ), procedure='null', is_constraint=True, inherit=True) rn_upd_trigger = dbops.AlterTriggerRenameTo( upd_trigger, new_name=new_upd_trg_name) return (rn_ins_trigger, rn_upd_trigger)
def _compile_set_in_singleton_mode( node: irast.Set, *, ctx: context.CompilerContextLevel) -> pgast.BaseExpr: if isinstance(node, irast.EmptySet): return pgast.NullConstant() elif node.expr is not None: return dispatch.compile(node.expr, ctx=ctx) else: if node.rptr: ptrref = node.rptr.ptrref source = node.rptr.source if ptrref.parent_ptr is None and source.rptr is not None: raise RuntimeError('unexpectedly long path in simple expr') ptr_stor_info = pg_types.get_ptrref_storage_info( ptrref, resolve_type=False) colref = pgast.ColumnRef(name=[ptr_stor_info.column_name]) elif irtyputils.is_scalar(node.typeref): colref = pgast.ColumnRef( name=[common.edgedb_name_to_pg_name(str(node.typeref.id))]) else: colref = pgast.ColumnRef( name=[common.edgedb_name_to_pg_name(str(node.typeref.id))]) return colref
def get_id(self): raw_name = self.constraint.raw_constraint_name() name = common.edgedb_name_to_pg_name('{}#{}'.format( raw_name, self.index)) name = common.quote_ident(name) return '{} ON {} {}'.format(name, self.constraint.get_subject_type(), self.constraint.get_subject_name())
def _get_triggers(self, table_name, constraint, proc_name='null'): cname = constraint.raw_constraint_name() ins_trigger_name = common.edgedb_name_to_pg_name(cname + '_instrigger') ins_trigger = dbops.Trigger( name=ins_trigger_name, table_name=table_name, events=('insert', ), procedure=proc_name, is_constraint=True, inherit=True) upd_trigger_name = common.edgedb_name_to_pg_name(cname + '_updtrigger') condition = constraint.get_trigger_condition() upd_trigger = dbops.Trigger( name=upd_trigger_name, table_name=table_name, events=('update', ), procedure=proc_name, condition=condition, is_constraint=True, inherit=True) return ins_trigger, upd_trigger
def drop_constr_trigger(self, table_name, constraint): cname = constraint.raw_constraint_name() ins_trigger_name = common.edgedb_name_to_pg_name(cname + '_instrigger') ins_trigger = dbops.Trigger( name=ins_trigger_name, table_name=table_name, events=('insert', ), procedure='null', is_constraint=True, inherit=True) drop_ins_trigger = dbops.DropTrigger(ins_trigger) upd_trigger_name = common.edgedb_name_to_pg_name(cname + '_updtrigger') upd_trigger = dbops.Trigger( name=upd_trigger_name, table_name=table_name, events=('update', ), procedure='null', is_constraint=True, inherit=True) drop_upd_trigger = dbops.DropTrigger(upd_trigger) return [drop_ins_trigger, drop_upd_trigger]
def _compile_set_in_singleton_mode( node: irast.Set, *, ctx: context.CompilerContextLevel) -> pgast.BaseExpr: if isinstance(node, irast.EmptySet): return pgast.NullConstant() elif node.expr is not None: return dispatch.compile(node.expr, ctx=ctx) else: if node.rptr: ptrref = node.rptr.ptrref source = node.rptr.source if isinstance(ptrref, irast.TupleIndirectionPointerRef): tuple_val = dispatch.compile(source, ctx=ctx) set_expr = astutils.tuple_getattr( tuple_val, source.typeref, ptrref.shortname.name, ) return set_expr if ptrref.source_ptr is None and source.rptr is not None: raise errors.UnsupportedFeatureError( 'unexpectedly long path in simple expr') ptr_stor_info = pg_types.get_ptrref_storage_info( ptrref, resolve_type=False) colref = pgast.ColumnRef( name=[ptr_stor_info.column_name], nullable=node.rptr.dir_cardinality.can_be_zero()) else: name = [common.edgedb_name_to_pg_name(str(node.typeref.id))] if node.path_id.is_objtype_path(): name.append('id') colref = pgast.ColumnRef(name=name) return colref
def get(self, hint: str = '') -> str: alias = super().get(hint) return common.edgedb_name_to_pg_name(alias)
def constraint_name(self, quote=True): name = self.raw_constraint_name() name = common.edgedb_name_to_pg_name(name) return common.quote_ident(name) if quote else name
def numbered_constraint_name(self, i, quote=True): raw_name = self.raw_constraint_name() name = common.edgedb_name_to_pg_name('{}#{}'.format(raw_name, i)) return common.quote_ident(name) if quote else name
def get(self, hint=None): alias = super().get(hint) return common.edgedb_name_to_pg_name(alias)