Skip to content

Commit

Permalink
Rename and move test variables relating to sql2pgroll (#512)
Browse files Browse the repository at this point in the history
* Rename the test variables to match their operation type.
* Rename files to match the operation type.

Part of #504
  • Loading branch information
andrew-farries authored Dec 5, 2024
1 parent d94d3b4 commit 3b8c56e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 74 deletions.
12 changes: 6 additions & 6 deletions pkg/sql2pgroll/alter_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ func TestConvertAlterTableStatements(t *testing.T) {
}{
{
sql: "ALTER TABLE foo ALTER COLUMN a SET NOT NULL",
expectedOp: expect.AlterTableOp1,
expectedOp: expect.AlterColumnOp1,
},
{
sql: "ALTER TABLE foo ALTER COLUMN a DROP NOT NULL",
expectedOp: expect.AlterTableOp2,
expectedOp: expect.AlterColumnOp2,
},
{
sql: "ALTER TABLE foo ALTER COLUMN a SET DATA TYPE text",
expectedOp: expect.AlterTableOp3,
expectedOp: expect.AlterColumnOp3,
},
{
sql: "ALTER TABLE foo ALTER COLUMN a TYPE text",
expectedOp: expect.AlterTableOp3,
expectedOp: expect.AlterColumnOp3,
},
{
sql: "ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a)",
expectedOp: expect.AlterTableOp4,
expectedOp: expect.CreateConstraintOp1,
},
{
sql: "ALTER TABLE foo ADD CONSTRAINT bar UNIQUE (a, b)",
expectedOp: expect.AlterTableOp5,
expectedOp: expect.CreateConstraintOp2,
},
}

Expand Down
42 changes: 42 additions & 0 deletions pkg/sql2pgroll/expect/alter_column.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: Apache-2.0

package expect

import (
"github.com/xataio/pgroll/pkg/migrations"
"github.com/xataio/pgroll/pkg/sql2pgroll"
)

var AlterColumnOp1 = &migrations.OpAlterColumn{
Table: "foo",
Column: "a",
Nullable: ptr(false),
Up: sql2pgroll.PlaceHolderSQL,
Down: sql2pgroll.PlaceHolderSQL,
}

var AlterColumnOp2 = &migrations.OpAlterColumn{
Table: "foo",
Column: "a",
Nullable: ptr(true),
Up: sql2pgroll.PlaceHolderSQL,
Down: sql2pgroll.PlaceHolderSQL,
}

var AlterColumnOp3 = &migrations.OpAlterColumn{
Table: "foo",
Column: "a",
Type: ptr("text"),
Up: sql2pgroll.PlaceHolderSQL,
Down: sql2pgroll.PlaceHolderSQL,
}

var AlterColumnOp4 = &migrations.OpAlterColumn{
Table: "foo",
Column: "a",
Name: ptr("b"),
}

func ptr[T any](v T) *T {
return &v
}
66 changes: 0 additions & 66 deletions pkg/sql2pgroll/expect/alter_table.go

This file was deleted.

32 changes: 32 additions & 0 deletions pkg/sql2pgroll/expect/create_constraint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-License-Identifier: Apache-2.0

package expect

import (
"github.com/xataio/pgroll/pkg/migrations"
"github.com/xataio/pgroll/pkg/sql2pgroll"
)

var CreateConstraintOp1 = &migrations.OpCreateConstraint{
Type: migrations.OpCreateConstraintTypeUnique,
Name: "bar",
Table: "foo",
Columns: []string{"a"},
Down: map[string]string{"a": sql2pgroll.PlaceHolderSQL},
Up: map[string]string{"a": sql2pgroll.PlaceHolderSQL},
}

var CreateConstraintOp2 = &migrations.OpCreateConstraint{
Type: migrations.OpCreateConstraintTypeUnique,
Name: "bar",
Table: "foo",
Columns: []string{"a", "b"},
Down: map[string]string{
"a": sql2pgroll.PlaceHolderSQL,
"b": sql2pgroll.PlaceHolderSQL,
},
Up: map[string]string{
"a": sql2pgroll.PlaceHolderSQL,
"b": sql2pgroll.PlaceHolderSQL,
},
}
4 changes: 2 additions & 2 deletions pkg/sql2pgroll/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func TestConvertRenameColumnStatements(t *testing.T) {
}{
{
sql: "ALTER TABLE foo RENAME COLUMN a TO b",
expectedOp: expect.AlterTableOp6,
expectedOp: expect.AlterColumnOp4,
},
{
sql: "ALTER TABLE foo RENAME a TO b",
expectedOp: expect.AlterTableOp6,
expectedOp: expect.AlterColumnOp4,
},
}

Expand Down

0 comments on commit 3b8c56e

Please sign in to comment.