000000010.go 685 B

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