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
// Create the constraint using the index we just created
59
60
ifc.row["pk"] =="true" {
60
61
// 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
+
fmt.Printf("ALTER TABLE ONLY %s ADD CONSTRAINT %s PRIMARY KEY USING INDEX %s;\n", c.row["table_name"], c.row["index_name"], c.row["index_name"])
62
63
} elseifc.row["uq"] =="true" {
63
64
// 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
+
fmt.Printf("ALTER TABLE ONLY %s ADD CONSTRAINT %s UNIQUE USING INDEX %s;\n", c.row["table_name"], c.row["index_name"], c.row["index_name"])
65
66
}
66
67
}
67
68
}
68
69
69
70
// Drop generates SQL to drop the index and/or the constraint related to it
70
71
func (cIndexSchema) Drop() {
72
+
fmt.Println("--\n--Drop\n--")
71
73
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"])
74
+
fmt.Println("-- Warning, this may drop foreign keys pointing at this column. Make sure you re-run the FOREIGN_KEY diff after running this SQL.")
75
+
//fmt.Printf("ALTER TABLE ONLY %s DROP CONSTRAINT IF EXISTS %s CASCADE; -- %s\n", c.row["table_name"], c.row["index_name"], c.row["constraint_def"])
76
+
fmt.Printf("ALTER TABLE ONLY %s DROP CONSTRAINT IF EXISTS %s CASCADE;\n", c.row["table_name"], c.row["index_name"])
73
77
}
74
-
fmt.Printf("DROP INDEX IF EXISTS %s; -- %s \n", c.row["index_name"], c.row["index_def"])
78
+
// The second line has no index_def
79
+
//fmt.Printf("DROP INDEX IF EXISTS %s; -- %s \n", c.row["index_name"], c.row["index_def"])
80
+
fmt.Printf("DROP INDEX IF EXISTS %s;\n", c.row["index_name"])
75
81
}
76
82
77
83
// Change handles the case where the table and index name match, but the details do not
78
84
func (cIndexSchema) Change(objinterface{}) {
79
85
c2, ok:=obj.(*IndexSchema)
80
86
if!ok {
81
-
fmt.Println("Error!!!, change needs an IndexSchema instance", c2)
87
+
fmt.Println("-- Error!!!, change needs an IndexSchema instance", c2)
82
88
}
83
89
// Table and constraint name matches... We need to make sure the details match
0 commit comments