Files
sm-seo-plugin/updates/202610270001_create_golem15_seo_entries.go

57 lines
1.7 KiB
Go

package updates
import (
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
)
// createEntries creates golem15_seo_entries: one row per record and locale
// (D-01), keyed by the record's morph type, its id as text and the locale.
// Empty text means "inherit". data holds later fields (Phase 33 schema
// types, custom JSON-LD) without a migration each.
var createEntries = []*gormigrate.Migration{
{
ID: "202610270001_create_golem15_seo_entries",
Migrate: func(tx *gorm.DB) error {
for _, stmt := range []string{
`CREATE TABLE golem15_seo_entries (
id BIGSERIAL PRIMARY KEY,
model_type TEXT NOT NULL,
record_id TEXT NOT NULL,
locale TEXT NOT NULL DEFAULT '',
type_key TEXT NOT NULL DEFAULT '',
url TEXT NOT NULL DEFAULT '',
title TEXT NOT NULL DEFAULT '',
description TEXT NOT NULL DEFAULT '',
keyphrase TEXT NOT NULL DEFAULT '',
canonical TEXT NOT NULL DEFAULT '',
robots TEXT NOT NULL DEFAULT '',
og_title TEXT NOT NULL DEFAULT '',
og_description TEXT NOT NULL DEFAULT '',
og_image TEXT NOT NULL DEFAULT '',
effective_title TEXT NOT NULL DEFAULT '',
effective_description TEXT NOT NULL DEFAULT '',
data jsonb NOT NULL DEFAULT '{}',
created_at TIMESTAMP(0) NULL,
updated_at TIMESTAMP(0) NULL,
CONSTRAINT golem15_seo_entries_record_locale UNIQUE (model_type, record_id, locale)
)`,
`CREATE INDEX golem15_seo_entries_url ON golem15_seo_entries (url)`,
`CREATE INDEX golem15_seo_entries_type_key ON golem15_seo_entries (type_key)`,
} {
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_seo_entries`).Error
},
},
}
func init() {
Register(createEntries...)
}