Skip to content

Latest commit

 

History

History
57 lines (41 loc) · 2.69 KB

constraints.md

File metadata and controls

57 lines (41 loc) · 2.69 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
    • comment [string] - comment on a singular, named 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 (only necessary when creating multiple constraints)
      • referencesConstraintComment [string] - comment on the individual foreign key 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