Commit ca9c3cd3 authored by Andrew Godwin's avatar Andrew Godwin
Browse files

Add check constraint support - needed a few Field changes

parent 375178fc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -435,6 +435,9 @@ class BaseDatabaseFeatures(object):
    # Does it support foreign keys?
    supports_foreign_keys = True

    # Does it support CHECK constraints?
    supports_check_constraints = True

    def __init__(self, connection):
        self.connection = connection

+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ class BaseDatabaseCreation(object):
    destruction of test databases.
    """
    data_types = {}
    data_type_check_constraints = {}

    def __init__(self, connection):
        self.connection = connection
+1 −0
Original line number Diff line number Diff line
@@ -170,6 +170,7 @@ class DatabaseFeatures(BaseDatabaseFeatures):
    requires_explicit_null_ordering_when_grouping = True
    allows_primary_key_0 = False
    uses_savepoints = True
    supports_check_constraints = False

    def __init__(self, connection):
        super(DatabaseFeatures, self).__init__(connection)
+7 −2
Original line number Diff line number Diff line
@@ -26,14 +26,19 @@ class DatabaseCreation(BaseDatabaseCreation):
        'GenericIPAddressField': 'inet',
        'NullBooleanField':  'boolean',
        'OneToOneField':     'integer',
        'PositiveIntegerField': 'integer CHECK ("%(column)s" >= 0)',
        'PositiveSmallIntegerField': 'smallint CHECK ("%(column)s" >= 0)',
        'PositiveIntegerField': 'integer',
        'PositiveSmallIntegerField': 'smallint',
        'SlugField':         'varchar(%(max_length)s)',
        'SmallIntegerField': 'smallint',
        'TextField':         'text',
        'TimeField':         'time',
    }

    data_type_check_constraints = {
        'PositiveIntegerField': '"%(column)s" >= 0',
        'PositiveSmallIntegerField': '"%(column)s" >= 0',
    }

    def sql_table_creation_suffix(self):
        assert self.connection.settings_dict['TEST_COLLATION'] is None, "PostgreSQL does not support collation setting at database creation time."
        if self.connection.settings_dict['TEST_CHARSET']:
+1 −1
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
                kc.table_schema = %s AND
                kc.table_name = %s
        """, ["public", table_name])
        for constraint, column, kind in cursor.fetchall():
        for constraint, column in cursor.fetchall():
            # If we're the first column, make the record
            if constraint not in constraints:
                constraints[constraint] = {
Loading