Skip to content

Commit

Permalink
Add a multi-column test case for CREATE TABLE (#563)
Browse files Browse the repository at this point in the history
Add a multi-column test case for conversion of `CREATE TABLE` statements
to `pgroll` operations.

All other test cases are single-column. This commit adds a multi-column
test case with multiple constraints.
  • Loading branch information
andrew-farries authored Jan 2, 2025
1 parent 829586e commit c451b8d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/sql2pgroll/create_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
sql: "CREATE TABLE foo(a text[5][3])",
expectedOp: expect.CreateTableOp9,
},
{
sql: "CREATE TABLE foo(a serial PRIMARY KEY, b int DEFAULT 100 CHECK (b > 0), c text NOT NULL UNIQUE)",
expectedOp: expect.CreateTableOp21,
},
}

for _, tc := range tests {
Expand Down
26 changes: 26 additions & 0 deletions pkg/sql2pgroll/expect/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,29 @@ var CreateTableOp20 = &migrations.OpCreateTable{
},
},
}

var CreateTableOp21 = &migrations.OpCreateTable{
Name: "foo",
Columns: []migrations.Column{
{
Name: "a",
Type: "serial",
Pk: true,
},
{
Name: "b",
Type: "int",
Default: ptr("100"),
Check: &migrations.CheckConstraint{
Name: "foo_b_check",
Constraint: "b > 0",
},
Nullable: true,
},
{
Name: "c",
Type: "text",
Unique: true,
},
},
}

0 comments on commit c451b8d

Please sign in to comment.