You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fmt.Printf("-- Unexpected situation in index.go: there is no index_def for %s %s\n", c.row["table_name"], c.row["index_name"])
50
+
return
51
+
}
52
+
53
+
// Create the index
54
+
fmt.Println(c.row["index_def"])
55
+
//fmt.Println("--", c.row["constraint_def"])
56
+
57
+
ifc.row["constraint_def"] !="null" {
58
+
// Create the constraint using the index we just created
59
+
ifc.row["pk"] =="true" {
60
+
// Add primary key using the index
61
+
fmt.Printf("ALTER TABLE IF EXISTS ONLY %s ADD CONSTRAINT %s PRIMARY KEY USING INDEX %s;\n", c.row["table_name"], c.row["index_name"], c.row["index_name"])
62
+
} elseifc.row["uq"] =="true" {
63
+
// Add unique constraint using the index
64
+
fmt.Printf("ALTER TABLE IF EXISTS ONLY %s ADD CONSTRAINT %s UNIQUE USING INDEX %s;\n", c.row["table_name"], c.row["index_name"], c.row["index_name"])
65
+
}
49
66
}
50
-
fmt.Printf("CREATE %sINDEX %s ON %s (%s);\n", uniqueStr, c.row["index_name"], c.row["table_name"], c.row["column_names"])
51
67
}
52
68
53
-
// Drop generates SQL to drop the index
69
+
// Drop generates SQL to drop the index and/or the constraint related to it
54
70
func (cIndexSchema) Drop() {
55
-
fmt.Printf("DROP INDEX %s; -- %s ON (%s)\n", c.row["index_name"], c.row["table_name"], c.row["column_names"])
71
+
ifc.row["constraint_def"] !="null" {
72
+
fmt.Printf("ALTER TABLE IF EXISTS ONLY %s DROP CONSTRAINT IF EXISTS %s; -- %s\n", c.row["table_name"], c.row["index_name"], c.row["constraint_def"])
73
+
}
74
+
fmt.Printf("DROP INDEX IF EXISTS %s; -- %s \n", c.row["index_name"], c.row["index_def"])
56
75
}
57
76
58
77
// Change handles the case where the table and index name match, but the details do not
0 commit comments