package attach import ( "github.com/go-gormigrate/gormigrate/v2" "gorm.io/gorm" ) // Migrations creates Winter's system_files table. Folded from // modules/system/database/migrations/2013_10_01_000002_Db_System_Files.php // and 2025_04_10_000031_Db_Add_System_Files_Metadata.php. var Migrations = []*gormigrate.Migration{ { ID: "202609180001_create_system_files", Migrate: func(tx *gorm.DB) error { stmts := []string{ `CREATE TABLE system_files ( id SERIAL PRIMARY KEY, disk_name TEXT NOT NULL, file_name TEXT NOT NULL, file_size INTEGER NOT NULL, content_type TEXT NOT NULL, title TEXT, description TEXT, field TEXT, attachment_id TEXT, attachment_type TEXT, is_public BOOLEAN NOT NULL DEFAULT TRUE, sort_order INTEGER, metadata TEXT, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW() )`, `CREATE INDEX system_files_field_index ON system_files (field)`, `CREATE INDEX system_files_attachment_id_index ON system_files (attachment_id)`, `CREATE INDEX system_files_attachment_type_index ON system_files (attachment_type)`, `CREATE INDEX system_files_attachment_lookup_index ON system_files (attachment_type, attachment_id, field)`, } for _, stmt := range stmts { 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 system_files").Error }, }, }