go: update atlas and test global-unique-id migration (#2661)

This commit is contained in:
Ariel Mashraki
2022-06-18 21:50:44 +03:00
committed by GitHub
parent 7017cbc898
commit 98d00a35b5
6 changed files with 28 additions and 11 deletions

View File

@@ -87,7 +87,7 @@ func (d *Postgres) setRange(ctx context.Context, conn dialect.ExecQuerier, t *Ta
if len(t.PrimaryKey) == 1 {
pk = t.PrimaryKey[0].Name
}
return conn.Exec(ctx, fmt.Sprintf("ALTER TABLE %s ALTER COLUMN %s RESTART WITH %d", t.Name, pk, value), []interface{}{}, nil)
return conn.Exec(ctx, fmt.Sprintf("ALTER TABLE %q ALTER COLUMN %q RESTART WITH %d", t.Name, pk, value), []interface{}{}, nil)
}
// table loads the current table description from the database.

View File

@@ -792,7 +792,7 @@ func TestPostgres_Create(t *testing.T) {
mock.ExpectExec(escape(`INSERT INTO "ent_types" ("type") VALUES ($1)`)).
WithArgs("users").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("ALTER TABLE users ALTER COLUMN id RESTART WITH 1").
mock.ExpectExec(`ALTER TABLE "users" ALTER COLUMN "id" RESTART WITH 1`).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.tableExists("groups", false)
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "groups"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, PRIMARY KEY("id"))`)).
@@ -801,7 +801,7 @@ func TestPostgres_Create(t *testing.T) {
mock.ExpectExec(escape(`INSERT INTO "ent_types" ("type") VALUES ($1)`)).
WithArgs("groups").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("ALTER TABLE groups ALTER COLUMN id RESTART WITH 4294967296").
mock.ExpectExec(`ALTER TABLE "groups" ALTER COLUMN "id" RESTART WITH 4294967296`).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},
@@ -837,7 +837,7 @@ func TestPostgres_Create(t *testing.T) {
mock.ExpectExec(escape(`INSERT INTO "ent_types" ("type") VALUES ($1)`)).
WithArgs("groups").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("ALTER TABLE groups ALTER COLUMN id RESTART WITH 4294967296").
mock.ExpectExec(`ALTER TABLE "groups" ALTER COLUMN "id" RESTART WITH 4294967296`).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},
@@ -860,7 +860,7 @@ func TestPostgres_Create(t *testing.T) {
mock.ExpectExec(escape(`CREATE TABLE IF NOT EXISTS "users"("id" bigint GENERATED BY DEFAULT AS IDENTITY NOT NULL, PRIMARY KEY("id"))`)).
WillReturnResult(sqlmock.NewResult(0, 1))
// set users id range (without inserting to ent_types).
mock.ExpectExec("ALTER TABLE users ALTER COLUMN id RESTART WITH 1").
mock.ExpectExec(`ALTER TABLE "users" ALTER COLUMN "id" RESTART WITH 1`).
WillReturnResult(sqlmock.NewResult(0, 1))
// query groups table.
mock.tableExists("groups", false)
@@ -870,7 +870,7 @@ func TestPostgres_Create(t *testing.T) {
mock.ExpectExec(escape(`INSERT INTO "ent_types" ("type") VALUES ($1)`)).
WithArgs("groups").
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectExec("ALTER TABLE groups ALTER COLUMN id RESTART WITH 4294967296").
mock.ExpectExec(`ALTER TABLE "groups" ALTER COLUMN "id" RESTART WITH 4294967296`).
WillReturnResult(sqlmock.NewResult(0, 1))
mock.ExpectCommit()
},