test(operator): write more unit tests

This commit is contained in:
grandwizard28 2025-07-21 18:29:57 +05:30
parent 072685af09
commit 30894885f0
No known key found for this signature in database
GPG Key ID: C7A26EDC5B7054B7

View File

@ -795,291 +795,291 @@ func TestOperatorAlterTable(t *testing.T) {
newTable *Table newTable *Table
expected map[OperatorSupport][][]byte expected map[OperatorSupport][][]byte
}{ }{
// { {
// name: "NoOperation", name: "NoOperation",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// }, },
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {}, {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {},
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {}, {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {},
// }, },
// }, },
// { {
// name: "RenameTable", name: "RenameTable",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users_new", Name: "users_new",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// []byte(`ALTER TABLE "users" RENAME TO "users_new"`), []byte(`ALTER TABLE "users" RENAME TO "users_new"`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" RENAME TO "users_new"`), []byte(`ALTER TABLE "users" RENAME TO "users_new"`),
// }, },
// }, },
// }, },
// { {
// name: "AddColumn_NullableNoDefault_SAlterTableAddAndDropColumnIfNotExistsAndExistsTrue", name: "AddColumn_NullableNoDefault_SAlterTableAddAndDropColumnIfNotExistsAndExistsTrue",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// }, },
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// {Name: "age", DataType: DataTypeInteger, Nullable: true, Default: ""}, {Name: "age", DataType: DataTypeInteger, Nullable: true, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// []byte(`ALTER TABLE "users" ADD COLUMN "age" INTEGER`), []byte(`ALTER TABLE "users" ADD COLUMN "age" INTEGER`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "age" INTEGER`), []byte(`ALTER TABLE "users" ADD COLUMN IF NOT EXISTS "age" INTEGER`),
// }, },
// }, },
// }, },
// { {
// name: "CreatePrimaryKeyConstraint", name: "CreatePrimaryKeyConstraint",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// PrimaryKeyConstraint: &PrimaryKeyConstraint{ PrimaryKeyConstraint: &PrimaryKeyConstraint{
// ColumnNames: []ColumnName{"id"}, ColumnNames: []ColumnName{"id"},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"))`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"))`),
// []byte(`INSERT INTO "users__temp" ("id") SELECT "id" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id") SELECT "id" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" ADD CONSTRAINT "pk_users" PRIMARY KEY ("id")`), []byte(`ALTER TABLE "users" ADD CONSTRAINT "pk_users" PRIMARY KEY ("id")`),
// }, },
// }, },
// }, },
// { {
// name: "DropPrimaryKeyConstraint_AlterColumnNullable", name: "DropPrimaryKeyConstraint_AlterColumnNullable",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: true, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: true, Default: ""},
// }, },
// PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}}, PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}},
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// // first drop to remove the primary key constraint // first drop to remove the primary key constraint
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT)`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT)`),
// []byte(`INSERT INTO "users__temp" ("id", "name") SELECT "id", "name" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "name") SELECT "id", "name" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// // second drop to make the column nullable // second drop to make the column nullable
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL)`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL)`),
// []byte(`INSERT INTO "users__temp" ("id", "name") SELECT "id", "name" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "name") SELECT "id", "name" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "pk_users"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "pk_users"`),
// []byte(`ALTER TABLE "users" ALTER COLUMN "name" SET NOT NULL`), []byte(`ALTER TABLE "users" ALTER COLUMN "name" SET NOT NULL`),
// }, },
// }, },
// }, },
// { {
// name: "DropForeignKeyConstraint_DropColumn", name: "DropForeignKeyConstraint_DropColumn",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{ ForeignKeyConstraints: []*ForeignKeyConstraint{
// {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"}, {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"},
// }, },
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{}, ForeignKeyConstraints: []*ForeignKeyConstraint{},
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// // first drop to remove the foreign key constraint // first drop to remove the foreign key constraint
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "org_id" INTEGER NOT NULL)`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "org_id" INTEGER NOT NULL)`),
// []byte(`INSERT INTO "users__temp" ("id", "org_id") SELECT "id", "org_id" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "org_id") SELECT "id", "org_id" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// // second drop to remove the column // second drop to remove the column
// []byte(`ALTER TABLE "users" DROP COLUMN "org_id"`), []byte(`ALTER TABLE "users" DROP COLUMN "org_id"`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// // first drop to remove the foreign key constraint // first drop to remove the foreign key constraint
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "fk_users_org_id"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "fk_users_org_id"`),
// // second drop to remove the column // second drop to remove the column
// []byte(`ALTER TABLE "users" DROP COLUMN IF EXISTS "org_id"`), []byte(`ALTER TABLE "users" DROP COLUMN IF EXISTS "org_id"`),
// }, },
// }, },
// }, },
// { {
// name: "DropMultipleConstraints", name: "DropMultipleConstraints",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "team_id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "team_id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}}, PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}},
// ForeignKeyConstraints: []*ForeignKeyConstraint{ ForeignKeyConstraints: []*ForeignKeyConstraint{
// {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"}, {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"},
// {ReferencingColumnName: "team_id", ReferencedTableName: "teams", ReferencedColumnName: "id"}, {ReferencingColumnName: "team_id", ReferencedTableName: "teams", ReferencedColumnName: "id"},
// }, },
// }, },
// uniqueConstraints: []*UniqueConstraint{ uniqueConstraints: []*UniqueConstraint{
// {ColumnNames: []ColumnName{"name", "age"}}, {ColumnNames: []ColumnName{"name", "age"}},
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "org_id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "team_id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "team_id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// ForeignKeyConstraints: []*ForeignKeyConstraint{ ForeignKeyConstraints: []*ForeignKeyConstraint{
// {ReferencingColumnName: "team_id", ReferencedTableName: "teams", ReferencedColumnName: "id"}, {ReferencingColumnName: "team_id", ReferencedTableName: "teams", ReferencedColumnName: "id"},
// }, },
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL, "age" INTEGER NOT NULL, "org_id" INTEGER NOT NULL, "team_id" INTEGER NOT NULL, CONSTRAINT "fk_users_team_id" FOREIGN KEY ("team_id") REFERENCES "teams" ("id"))`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL, "age" INTEGER NOT NULL, "org_id" INTEGER NOT NULL, "team_id" INTEGER NOT NULL, CONSTRAINT "fk_users_team_id" FOREIGN KEY ("team_id") REFERENCES "teams" ("id"))`),
// []byte(`INSERT INTO "users__temp" ("id", "name", "age", "org_id", "team_id") SELECT "id", "name", "age", "org_id", "team_id" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "name", "age", "org_id", "team_id") SELECT "id", "name", "age", "org_id", "team_id" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name_age" ON "users" ("name", "age")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name_age" ON "users" ("name", "age")`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "pk_users"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "pk_users"`),
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "fk_users_org_id"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "fk_users_org_id"`),
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "uq_users_name_age"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "uq_users_name_age"`),
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name_age" ON "users" ("name", "age")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name_age" ON "users" ("name", "age")`),
// }, },
// }, },
// }, },
// { {
// name: "DropUniqueConstraints_AlterMultipleColumns", name: "DropUniqueConstraints_AlterMultipleColumns",
// table: &Table{ table: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: true, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: true, Default: ""},
// {Name: "age", DataType: DataTypeInteger, Nullable: true, Default: ""}, {Name: "age", DataType: DataTypeInteger, Nullable: true, Default: ""},
// {Name: "email", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "email", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}}, PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}},
// ForeignKeyConstraints: []*ForeignKeyConstraint{ ForeignKeyConstraints: []*ForeignKeyConstraint{
// {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"}, {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"},
// }, },
// }, },
// uniqueConstraints: []*UniqueConstraint{ uniqueConstraints: []*UniqueConstraint{
// {ColumnNames: []ColumnName{"email"}}, {ColumnNames: []ColumnName{"email"}},
// {name: "my_name_constraint", ColumnNames: []ColumnName{"name"}}, {name: "my_name_constraint", ColumnNames: []ColumnName{"name"}},
// }, },
// newTable: &Table{ newTable: &Table{
// Name: "users", Name: "users",
// Columns: []*Column{ Columns: []*Column{
// {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "id", DataType: DataTypeInteger, Nullable: false, Default: ""},
// {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""}, {Name: "name", DataType: DataTypeText, Nullable: false, Default: ""},
// {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: "0"}, {Name: "age", DataType: DataTypeInteger, Nullable: false, Default: "0"},
// {Name: "email", DataType: DataTypeInteger, Nullable: false, Default: ""}, {Name: "email", DataType: DataTypeInteger, Nullable: false, Default: ""},
// }, },
// PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}}, PrimaryKeyConstraint: &PrimaryKeyConstraint{ColumnNames: []ColumnName{"id"}},
// ForeignKeyConstraints: []*ForeignKeyConstraint{ ForeignKeyConstraints: []*ForeignKeyConstraint{
// {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"}, {ReferencingColumnName: "org_id", ReferencedTableName: "orgs", ReferencedColumnName: "id"},
// }, },
// }, },
// expected: map[OperatorSupport][][]byte{ expected: map[OperatorSupport][][]byte{
// {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: { {SCreateAndDropConstraint: false, SAlterTableAddAndDropColumnIfNotExistsAndExists: false, SAlterTableAlterColumnSetAndDrop: false}: {
// // first drop to remove unique constraint // first drop to remove unique constraint
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT, "age" INTEGER, "email" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"), CONSTRAINT "fk_users_org_id" FOREIGN KEY ("org_id") REFERENCES "orgs" ("id"))`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT, "age" INTEGER, "email" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"), CONSTRAINT "fk_users_org_id" FOREIGN KEY ("org_id") REFERENCES "orgs" ("id"))`),
// []byte(`INSERT INTO "users__temp" ("id", "name", "age", "email") SELECT "id", "name", "age", "email" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "name", "age", "email") SELECT "id", "name", "age", "email" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// // second drop to change all columns // second drop to change all columns
// []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL, "age" INTEGER NOT NULL DEFAULT 0, "email" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"), CONSTRAINT "fk_users_org_id" FOREIGN KEY ("org_id") REFERENCES "orgs" ("id"))`), []byte(`CREATE TABLE IF NOT EXISTS "users__temp" ("id" INTEGER NOT NULL, "name" TEXT NOT NULL, "age" INTEGER NOT NULL DEFAULT 0, "email" INTEGER NOT NULL, CONSTRAINT "pk_users" PRIMARY KEY ("id"), CONSTRAINT "fk_users_org_id" FOREIGN KEY ("org_id") REFERENCES "orgs" ("id"))`),
// []byte(`INSERT INTO "users__temp" ("id", "name", "age", "email") SELECT "id", "name", "age", "email" FROM "users"`), []byte(`INSERT INTO "users__temp" ("id", "name", "age", "email") SELECT "id", "name", "age", "email" FROM "users"`),
// []byte(`DROP TABLE IF EXISTS "users"`), []byte(`DROP TABLE IF EXISTS "users"`),
// []byte(`ALTER TABLE "users__temp" RENAME TO "users"`), []byte(`ALTER TABLE "users__temp" RENAME TO "users"`),
// // create unique index for the constraint // create unique index for the constraint
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_email" ON "users" ("email")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_email" ON "users" ("email")`),
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name" ON "users" ("name")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name" ON "users" ("name")`),
// }, },
// {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: { {SCreateAndDropConstraint: true, SAlterTableAddAndDropColumnIfNotExistsAndExists: true, SAlterTableAlterColumnSetAndDrop: true}: {
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "uq_users_email"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "uq_users_email"`),
// []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "my_name_constraint"`), []byte(`ALTER TABLE "users" DROP CONSTRAINT IF EXISTS "my_name_constraint"`),
// []byte(`ALTER TABLE "users" ALTER COLUMN "name" SET NOT NULL`), []byte(`ALTER TABLE "users" ALTER COLUMN "name" SET NOT NULL`),
// []byte(`ALTER TABLE "users" ALTER COLUMN "age" SET NOT NULL`), []byte(`ALTER TABLE "users" ALTER COLUMN "age" SET NOT NULL`),
// []byte(`ALTER TABLE "users" ALTER COLUMN "age" SET DEFAULT 0`), []byte(`ALTER TABLE "users" ALTER COLUMN "age" SET DEFAULT 0`),
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_email" ON "users" ("email")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_email" ON "users" ("email")`),
// []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name" ON "users" ("name")`), []byte(`CREATE UNIQUE INDEX IF NOT EXISTS "uq_users_name" ON "users" ("name")`),
// }, },
// }, },
// }, },
{ {
name: "ChangePrimaryKeyConstraint", name: "ChangePrimaryKeyConstraint",
table: &Table{ table: &Table{