Skip to content

Commit c451b8d

Browse files
Add a multi-column test case for CREATE TABLE (#563)
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.
1 parent 829586e commit c451b8d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

pkg/sql2pgroll/create_table_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func TestConvertCreateTableStatements(t *testing.T) {
160160
sql: "CREATE TABLE foo(a text[5][3])",
161161
expectedOp: expect.CreateTableOp9,
162162
},
163+
{
164+
sql: "CREATE TABLE foo(a serial PRIMARY KEY, b int DEFAULT 100 CHECK (b > 0), c text NOT NULL UNIQUE)",
165+
expectedOp: expect.CreateTableOp21,
166+
},
163167
}
164168

165169
for _, tc := range tests {

pkg/sql2pgroll/expect/create_table.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,29 @@ var CreateTableOp20 = &migrations.OpCreateTable{
268268
},
269269
},
270270
}
271+
272+
var CreateTableOp21 = &migrations.OpCreateTable{
273+
Name: "foo",
274+
Columns: []migrations.Column{
275+
{
276+
Name: "a",
277+
Type: "serial",
278+
Pk: true,
279+
},
280+
{
281+
Name: "b",
282+
Type: "int",
283+
Default: ptr("100"),
284+
Check: &migrations.CheckConstraint{
285+
Name: "foo_b_check",
286+
Constraint: "b > 0",
287+
},
288+
Nullable: true,
289+
},
290+
{
291+
Name: "c",
292+
Type: "text",
293+
Unique: true,
294+
},
295+
},
296+
}

0 commit comments

Comments
 (0)