000000006.go 905 B

1234567891011121314151617181920212223242526272829303132333435
  1. package migrate
  2. import (
  3. "golang-fave/engine/sqlw"
  4. )
  5. func Migrate_000000006(db *sqlw.DB, host string) error {
  6. // Table: shop_product_images
  7. if _, err := db.Exec(
  8. `CREATE TABLE shop_product_images (
  9. product_id int(11) NOT NULL,
  10. filename varchar(255) NOT NULL
  11. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;`,
  12. ); err != nil {
  13. return err
  14. }
  15. // Indexes
  16. if _, err := db.Exec(`ALTER TABLE shop_product_images ADD UNIQUE KEY product_filename (product_id,filename) USING BTREE;`); err != nil {
  17. return err
  18. }
  19. if _, err := db.Exec(`ALTER TABLE shop_product_images ADD KEY FK_shop_product_images_product_id (product_id);`); err != nil {
  20. return err
  21. }
  22. // References
  23. if _, err := db.Exec(`
  24. ALTER TABLE shop_product_images ADD CONSTRAINT FK_shop_product_images_product_id
  25. FOREIGN KEY (product_id) REFERENCES shop_products (id) ON DELETE RESTRICT;
  26. `); err != nil {
  27. return err
  28. }
  29. return nil
  30. }