Skip to content

Commit

Permalink
Add testcases for NOT DEFERRABLE constraints
Browse files Browse the repository at this point in the history
`NOT DEFERRABLE` constraints are the default behhavior in PostgreSQL, so
they should be converted to the same operations as when `NOT DEFERRABLE`
is not specified.
  • Loading branch information
andrew-farries committed Dec 19, 2024
1 parent 627b64e commit 48169e6
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a int UNIQUE)",
expectedOp: expect.CreateTableOp5,
},
{
sql: "CREATE TABLE foo(a int UNIQUE NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp5,
},
{
sql: "CREATE TABLE foo(a int PRIMARY KEY)",
expectedOp: expect.CreateTableOp6,
},
{
sql: "CREATE TABLE foo(a int PRIMARY KEY NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp6,
},
{
sql: "CREATE TABLE foo(a int CHECK (a > 0))",
expectedOp: expect.CreateTableOp10,
Expand All @@ -49,33 +57,57 @@ func TestConvertCreateTableStatements(t *testing.T) {
expectedOp: expect.CreateTableOp11,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b))",
sql: "CREATE TABLE foo(a int REFERENCES bar(b) NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON UPDATE NO ACTION)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON UPDATE NO ACTION NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE NO ACTION)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE NO ACTION NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp12,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE RESTRICT)",
expectedOp: expect.CreateTableOp13,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE RESTRICT NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp13,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE SET NULL)",
expectedOp: expect.CreateTableOp14,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE SET NULL NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp14,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE SET DEFAULT)",
expectedOp: expect.CreateTableOp15,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE SET DEFAULT NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp15,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE CASCADE)",
expectedOp: expect.CreateTableOp16,
},
{
sql: "CREATE TABLE foo(a int REFERENCES bar(b) ON DELETE CASCADE NOT DEFERRABLE)",
expectedOp: expect.CreateTableOp16,
},
{
sql: "CREATE TABLE foo(a varchar(255))",
expectedOp: expect.CreateTableOp3,
Expand Down

0 comments on commit 48169e6

Please sign in to comment.