fix: contain generated files and assets and harden SQL rendering
This commit is contained in:
@@ -57,8 +57,8 @@ func TestDiffStatements(t *testing.T) {
|
||||
current: func() *models.Database {
|
||||
return diffTestDB("public", map[string]map[string]string{"users": {"id": "integer"}})
|
||||
},
|
||||
wantContain: []string{"CREATE TABLE IF NOT EXISTS public.posts"},
|
||||
wantAbsent: []string{"public.users"},
|
||||
wantContain: []string{"CREATE TABLE IF NOT EXISTS \"public\".\"posts\""},
|
||||
wantAbsent: []string{"\"public\".\"users\""},
|
||||
},
|
||||
{
|
||||
name: "missing column is added and existing columns are skipped",
|
||||
@@ -68,7 +68,7 @@ func TestDiffStatements(t *testing.T) {
|
||||
current: func() *models.Database {
|
||||
return diffTestDB("public", map[string]map[string]string{"users": {"id": "integer"}})
|
||||
},
|
||||
wantContain: []string{"ADD COLUMN IF NOT EXISTS email text"},
|
||||
wantContain: []string{"ADD COLUMN IF NOT EXISTS \"email\" text"},
|
||||
wantAbsent: []string{"COLUMN id"},
|
||||
},
|
||||
{
|
||||
@@ -79,7 +79,7 @@ func TestDiffStatements(t *testing.T) {
|
||||
current: func() *models.Database {
|
||||
return diffTestDB("public", map[string]map[string]string{"users": {"id": "integer"}})
|
||||
},
|
||||
wantContain: []string{"ALTER COLUMN id TYPE bigint"},
|
||||
wantContain: []string{"ALTER COLUMN \"id\" TYPE bigint"},
|
||||
},
|
||||
{
|
||||
name: "missing non-public schema is created before its tables",
|
||||
@@ -88,8 +88,8 @@ func TestDiffStatements(t *testing.T) {
|
||||
},
|
||||
current: func() *models.Database { return models.InitDatabase("testdb") },
|
||||
wantContain: []string{
|
||||
"CREATE SCHEMA IF NOT EXISTS app",
|
||||
"CREATE TABLE IF NOT EXISTS app.users",
|
||||
"CREATE SCHEMA IF NOT EXISTS \"app\"",
|
||||
"CREATE TABLE IF NOT EXISTS \"app\".\"users\"",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -149,7 +149,7 @@ func TestDiffStatements_NewTableCreatesPrimaryKeySequence(t *testing.T) {
|
||||
id := models.InitColumn("id", "users", "public")
|
||||
id.Type = "integer"
|
||||
id.IsPrimaryKey = true
|
||||
id.Default = "nextval('public.users_id_seq'::regclass)"
|
||||
id.Default = "nextval('\"public\".\"users_id_seq\"'::regclass)"
|
||||
table.Columns["id"] = id
|
||||
schema.Tables = append(schema.Tables, table)
|
||||
model.Schemas = append(model.Schemas, schema)
|
||||
@@ -160,7 +160,7 @@ func TestDiffStatements_NewTableCreatesPrimaryKeySequence(t *testing.T) {
|
||||
t.Fatalf("diffStatements failed: %v", err)
|
||||
}
|
||||
out := diffJoin(stmts)
|
||||
if !strings.Contains(out, "CREATE SEQUENCE IF NOT EXISTS public.users_id_seq") {
|
||||
if !strings.Contains(out, "CREATE SEQUENCE IF NOT EXISTS \"public\".\"users_id_seq\"") {
|
||||
t.Fatalf("expected sequence creation, got:\n%s", out)
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ func TestDiffStatements_NewIndexAndChangedIndexRecreated(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("diffStatements failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(diffJoin(stmts), "CREATE INDEX IF NOT EXISTS idx_users_lookup") {
|
||||
if !strings.Contains(diffJoin(stmts), "CREATE INDEX IF NOT EXISTS \"idx_users_lookup\"") {
|
||||
t.Fatalf("expected index creation, got:\n%s", diffJoin(stmts))
|
||||
}
|
||||
|
||||
@@ -329,7 +329,7 @@ func TestDiffStatements_ChangedPrimaryKeyIsRecreated(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("diffStatements failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(diffJoin(stmts), "DROP CONSTRAINT IF EXISTS pk_public_users") {
|
||||
if !strings.Contains(diffJoin(stmts), "DROP CONSTRAINT IF EXISTS \"pk_public_users\"") {
|
||||
t.Fatalf("expected old primary key to be dropped, got:\n%s", diffJoin(stmts))
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ func TestDiffStatements_ChangedCommentEmitted(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("diffStatements failed: %v", err)
|
||||
}
|
||||
if !strings.Contains(diffJoin(stmts), "COMMENT ON TABLE public.users IS 'new'") {
|
||||
if !strings.Contains(diffJoin(stmts), "COMMENT ON TABLE \"public\".\"users\" IS 'new'") {
|
||||
t.Fatalf("expected changed comment, got:\n%s", diffJoin(stmts))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user