000000010.go 635 B

123456789101112131415161718192021222324252627
  1. package migrate
  2. import (
  3. "golang-fave/engine/sqlw"
  4. )
  5. func Migrate_000000010(db *sqlw.DB, host string) error {
  6. // Changes
  7. if _, err := db.Exec(`ALTER TABLE shop_products ADD COLUMN parent_id INT(11) DEFAULT NULL AFTER id;`); err != nil {
  8. return err
  9. }
  10. // Indexes
  11. if _, err := db.Exec(`ALTER TABLE shop_products ADD KEY FK_shop_products_parent_id (parent_id);`); err != nil {
  12. return err
  13. }
  14. // References
  15. if _, err := db.Exec(`
  16. ALTER TABLE shop_products ADD CONSTRAINT FK_shop_products_parent_id
  17. FOREIGN KEY (parent_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  18. `); err != nil {
  19. return err
  20. }
  21. return nil
  22. }