diff --git a/lib/SQL/Translator/Producer/PostgreSQL.pm b/lib/SQL/Translator/Producer/PostgreSQL.pm index 7520563ff..6b6dc0fae 100644 --- a/lib/SQL/Translator/Producer/PostgreSQL.pm +++ b/lib/SQL/Translator/Producer/PostgreSQL.pm @@ -939,6 +939,11 @@ sub alter_drop_constraint { my ($c, $options) = @_; my $generator = _generator($options); + # NOT NULL constraint does not require a DROP CONSTRAINT statement + if ( $c->type eq NOT_NULL) { + return; + } + # attention: Postgres has a very special naming structure for naming # foreign keys and primary keys. It names them using the name of the # table as prefix and fkey or pkey as suffix, concatenated by an underscore diff --git a/t/30sqlt-new-diff-pgsql.t b/t/30sqlt-new-diff-pgsql.t index 471dc8f43..d3fbd7a35 100644 --- a/t/30sqlt-new-diff-pgsql.t +++ b/t/30sqlt-new-diff-pgsql.t @@ -78,6 +78,8 @@ ALTER TABLE "person" ALTER COLUMN "name" SET NOT NULL; ALTER TABLE "person" ALTER COLUMN "age" SET DEFAULT 18; +ALTER TABLE "person" ALTER COLUMN "weight" DROP NOT NULL; + ALTER TABLE "person" ALTER COLUMN "iq" TYPE bigint; ALTER TABLE "person" ALTER COLUMN "nickname" SET NOT NULL; @@ -133,6 +135,8 @@ ALTER TABLE person ALTER COLUMN name SET NOT NULL; ALTER TABLE person ALTER COLUMN age SET DEFAULT 18; +ALTER TABLE person ALTER COLUMN weight DROP NOT NULL; + ALTER TABLE person ALTER COLUMN iq TYPE bigint; ALTER TABLE person ALTER COLUMN nickname SET NOT NULL; diff --git a/t/data/diff/pgsql/create1.yml b/t/data/diff/pgsql/create1.yml index d31314641..04b47c06a 100644 --- a/t/data/diff/pgsql/create1.yml +++ b/t/data/diff/pgsql/create1.yml @@ -135,6 +135,18 @@ schema: reference_fields: [] reference_table: '' type: UNIQUE + - deferrable: 1 + expression: '' + fields: + - weight + match_type: '' + name: '' + on_delete: '' + on_update: '' + options: [] + reference_fields: [] + reference_table: '' + type: NOT_NULL fields: age: data_type: int @@ -194,7 +206,7 @@ schema: data_type: numeric default_value: ~ extra: {} - is_nullable: 1 + is_nullable: 0 is_primary_key: 0 is_unique: 0 name: weight