Skip to content

Latest commit

 

History

History
55 lines (39 loc) · 2.48 KB

constraints.md

File metadata and controls

55 lines (39 loc) · 2.48 KB

Constraint Operations

pgm.addConstraint( tablename, constraint_name, expression )

Add a named column constraint - postgres docs

Arguments:

  • tablename [Name] - name of the table to alter
  • constraint_name [string] - name for the constraint
  • expression [string or object] - constraint expression (raw sql) or definition:
    • check [string or array] - sql for a check constraint(s)
    • unique [Name or array of Names or array of arrays of Names] - names of unique columns
    • primaryKey [Name or array of Names] - names of primary columns
    • exclude [string] - sql for an exclude constraint
    • deferrable [boolean] - flag for deferrable table constraint
    • deferred [boolean] - flag for initially deferred deferrable table constraint
    • foreignKeys [object or array of objects] - foreign keys specification
      • columns [Name or array of Names] - names of columns
      • references [Name] - names of foreign table and column names
      • referencesConstraintName [string] - name of the created constraint
      • onDelete [string] - action to perform on delete
      • onUpdate [string] - action to perform on update
      • match [string] - FULL or SIMPLE

Aliases: createConstraint Reverse Operation: dropConstraint


pgm.dropConstraint( tablename, constraint_name, options )

Drop a named column constraint - postgres docs

Arguments:

  • tablename [Name] - name of the table to alter
  • constraint_name [string] - name for the constraint
  • options [object] - options:
    • ifExists [boolean] - drops constraint only if it exists
    • cascade [boolean] - drops also dependent objects

pgm.renameConstraint( tablename, old_constraint_name, new_constraint_name )


Rename a constraint - postgres docs

Arguments:

  • tablename [Name] - name of the table to alter
  • old_constraint_name [string] - current constraint name
  • new_constraint_name [string] - new constraint name

Reverse Operation: same operation in opposite direction