package updates import ( "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) // createImageVariants creates golem15_journal_image_variants (P33-43): one // row per featured image and width with the thumbnail's key, its WebP // copy's key and the original's size. file_id names a system_files row // without a foreign key (the plugin's migrations run without the framework // tables in its tests); the API deletes the rows with the file, and rows // of a file removed elsewhere are never listed. var createImageVariants = []*gormigrate.Migration{ { ID: "202610280002_create_golem15_journal_image_variants", Migrate: func(tx *gorm.DB) error { if err := tx.Exec(`CREATE TABLE golem15_journal_image_variants ( id BIGSERIAL PRIMARY KEY, file_id BIGINT NOT NULL, width INTEGER NOT NULL, height INTEGER NOT NULL, key TEXT NOT NULL, webp_key TEXT NOT NULL, source_width INTEGER NOT NULL, source_height INTEGER NOT NULL, created_at TIMESTAMP(0) NULL )`).Error; err != nil { return err } return tx.Exec(`CREATE UNIQUE INDEX golem15_journal_image_variants_file_width ON golem15_journal_image_variants (file_id, width)`).Error }, Rollback: func(tx *gorm.DB) error { return tx.Exec(`DROP TABLE IF EXISTS golem15_journal_image_variants`).Error }, }, } func init() { Register(createImageVariants...) }