Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename and move test variables relating to sql2pgroll #512

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading