feat: SEO change history
This commit is contained in:
49
updates/202610270002_create_golem15_seo_revisions.go
Normal file
49
updates/202610270002_create_golem15_seo_revisions.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createRevisions creates golem15_seo_revisions: the SEO change history
|
||||
// (D-13) with author, via, subject, a readable description and the changed
|
||||
// fields before and after; undo marks a change undone.
|
||||
var createRevisions = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610270002_create_golem15_seo_revisions",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
for _, stmt := range []string{
|
||||
`CREATE TABLE golem15_seo_revisions (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
batch_id TEXT NULL,
|
||||
author_id BIGINT NULL,
|
||||
author_label TEXT NOT NULL DEFAULT '',
|
||||
via TEXT NOT NULL,
|
||||
subject_kind TEXT NOT NULL,
|
||||
subject_id TEXT NOT NULL DEFAULT '',
|
||||
what TEXT NOT NULL DEFAULT '',
|
||||
before jsonb NULL,
|
||||
after jsonb NULL,
|
||||
undone_at TIMESTAMP(0) NULL,
|
||||
undone_by_id BIGINT NULL,
|
||||
created_at TIMESTAMP(0) NOT NULL DEFAULT NOW()
|
||||
)`,
|
||||
`CREATE INDEX golem15_seo_revisions_subject ON golem15_seo_revisions (subject_kind, subject_id)`,
|
||||
`CREATE INDEX golem15_seo_revisions_created ON golem15_seo_revisions (created_at DESC)`,
|
||||
`CREATE INDEX golem15_seo_revisions_batch ON golem15_seo_revisions (batch_id) WHERE batch_id IS NOT NULL`,
|
||||
} {
|
||||
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_revisions`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createRevisions...)
|
||||
}
|
||||
Reference in New Issue
Block a user