package updates import ( "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) // createMenuEntries creates golem15_menu_menu_entries with the PHP columns // (v1.0.1 create_menu_entries_table): the menu, the tree columns (parent_id, // the NestedTree nest columns and sort_order), the entry's type, title, URL // and reference, and its display attributes. var createMenuEntries = []*gormigrate.Migration{ { ID: "202610110002_create_golem15_menu_menu_entries", Migrate: func(tx *gorm.DB) error { for _, stmt := range []string{ `CREATE TABLE golem15_menu_menu_entries ( id SERIAL PRIMARY KEY, menu_id INTEGER NOT NULL, parent_id INTEGER NULL, nest_left INTEGER NOT NULL, nest_right INTEGER NOT NULL, nest_depth INTEGER NOT NULL, sort_order INTEGER NULL, type VARCHAR(255) NOT NULL, title VARCHAR(255) NOT NULL, url VARCHAR(255) NULL, reference VARCHAR(255) NULL, code VARCHAR(255) NULL, icon VARCHAR(255) NULL, css_class VARCHAR(255) NULL, target VARCHAR(255) NULL, is_published BOOLEAN NOT NULL DEFAULT true, created_at TIMESTAMPTZ NULL, updated_at TIMESTAMPTZ NULL )`, `CREATE INDEX golem15_menu_menu_entries_menu_parent_sort_index ON golem15_menu_menu_entries (menu_id, parent_id, sort_order)`, } { if err := tx.Exec(stmt).Error; err != nil { return err } } return nil }, Rollback: func(tx *gorm.DB) error { return tx.Exec(`DROP TABLE IF EXISTS golem15_menu_menu_entries`).Error }, }, } func init() { Register(createMenuEntries...) }