How to use the pglast.enums.ConstrType function in pglast

To help you get started, we’ve selected a few pglast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github erik / squabble / squabble / rules / disallow_foreign_key.py View on Github external
def _check_constraint(child_ctx, constraint):
            if constraint.contype == ConstrType.CONSTR_FOREIGN:
                child_ctx.report(
                    self.DisallowedForeignKeyConstraint(table=table_name),
                    node=constraint
                )
github erik / squabble / squabble / rules / require_foreign_key.py View on Github external
>>> _column_needs_foreign_key(fk_regex, pglast.Node(cols['email']))
    False
    >>> _column_needs_foreign_key(fk_regex, pglast.Node(cols['users_id']))
    True
    >>> _column_needs_foreign_key(fk_regex, pglast.Node(cols['post_id']))
    False
    """
    name = column_def.colname.value
    if not fk_regex.match(name):
        return False

    if column_def.constraints == pglast.Missing:
        return True

    return not any(
        e.contype == ConstrType.CONSTR_FOREIGN
        for e in column_def.constraints
    )
github erik / squabble / squabble / rules / add_column_disallow_constraints.py View on Github external
{
           "AddColumnDisallowConstraints": {
               "disallowed": ["DEFAULT", "FOREIGN"]
           }
       }

    Valid constraint types:
      - DEFAULT
      - NULL
      - NOT NULL
      - FOREIGN
      - UNIQUE
    """

    _CONSTRAINT_MAP = {
        'DEFAULT': ConstrType.CONSTR_DEFAULT,
        'NULL': ConstrType.CONSTR_NULL,
        'NOT NULL': ConstrType.CONSTR_NOTNULL,
        'FOREIGN': ConstrType.CONSTR_FOREIGN,
        'UNIQUE': ConstrType.CONSTR_UNIQUE,
    }

    class ConstraintNotAllowed(Message):
        """
        When adding a column to an existing table, certain constraints can have
        unintentional side effects, like locking the table or introducing
        performance issues.

        For example, adding a ``DEFAULT`` constraint may hold a lock on the
        table while all existing rows are modified to fill in the default
        value.
github lelit / pglast / pglast / printers / ddl.py View on Github external
def constraint(node, output):
    if node.conname:
        output.swrite('CONSTRAINT ')
        output.print_name(node.conname)
    ct = enums.ConstrType
    if node.contype == ct.CONSTR_NULL:
        output.swrite('NULL')
    elif node.contype == ct.CONSTR_DEFAULT:
        output.swrite('DEFAULT ')
        # """
        # we may have the expression in either "raw" form [...]  or "cooked" form [...]
        # should never have both in the same node!
        # """
        output.print_node(node.raw_expr or node.cooked_expr)
    elif node.contype == ct.CONSTR_NOTNULL:
        output.swrite('NOT NULL')
    elif node.contype == ct.CONSTR_CHECK:
        output.swrite('CHECK (')
        output.print_node(node.raw_expr or node.cooked_expr)
        output.write(')')
        if node.is_no_inherit:
github erik / squabble / squabble / rules / add_column_disallow_constraints.py View on Github external
"disallowed": ["DEFAULT", "FOREIGN"]
           }
       }

    Valid constraint types:
      - DEFAULT
      - NULL
      - NOT NULL
      - FOREIGN
      - UNIQUE
    """

    _CONSTRAINT_MAP = {
        'DEFAULT': ConstrType.CONSTR_DEFAULT,
        'NULL': ConstrType.CONSTR_NULL,
        'NOT NULL': ConstrType.CONSTR_NOTNULL,
        'FOREIGN': ConstrType.CONSTR_FOREIGN,
        'UNIQUE': ConstrType.CONSTR_UNIQUE,
    }

    class ConstraintNotAllowed(Message):
        """
        When adding a column to an existing table, certain constraints can have
        unintentional side effects, like locking the table or introducing
        performance issues.

        For example, adding a ``DEFAULT`` constraint may hold a lock on the
        table while all existing rows are modified to fill in the default
        value.

        A ``UNIQUE`` constraint will require scanning the table to confirm
        there are no duplicates.
github erik / squabble / squabble / rules / require_primary_key.py View on Github external
def _check_constraint(_ctx, constraint):
            nonlocal seen_pk

            if constraint.contype == ConstrType.CONSTR_PRIMARY:
                seen_pk = True