feat: URL rules and the settings singleton
This commit is contained in:
63
updates/202610270003_create_golem15_seo_settings.go
Normal file
63
updates/202610270003_create_golem15_seo_settings.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createSettings creates the settings singleton golem15_seo_settings (row
|
||||
// id 1) with the default templates, address options and the seeded D-07
|
||||
// query-parameter list. The robots.txt columns are added by a later
|
||||
// migration.
|
||||
var createSettings = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610270003_create_golem15_seo_settings",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
for _, stmt := range []string{
|
||||
`CREATE TABLE golem15_seo_settings (
|
||||
id INTEGER PRIMARY KEY,
|
||||
site_name TEXT NOT NULL DEFAULT '',
|
||||
twitter_site TEXT NOT NULL DEFAULT '',
|
||||
title_template TEXT NOT NULL DEFAULT '%title% | %site%',
|
||||
home_template TEXT NOT NULL DEFAULT '%site%',
|
||||
default_description TEXT NOT NULL DEFAULT '',
|
||||
default_og_image TEXT NOT NULL DEFAULT '',
|
||||
query_params jsonb NULL,
|
||||
noindex_paths TEXT NOT NULL DEFAULT '',
|
||||
search_paths TEXT NOT NULL DEFAULT '',
|
||||
url_host TEXT NOT NULL DEFAULT 'keep',
|
||||
url_slash TEXT NOT NULL DEFAULT 'keep',
|
||||
url_lowercase BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
verify_google TEXT NOT NULL DEFAULT '',
|
||||
verify_bing TEXT NOT NULL DEFAULT '',
|
||||
verify_yandex TEXT NOT NULL DEFAULT '',
|
||||
verify_other jsonb NULL,
|
||||
verify_files jsonb NULL,
|
||||
csv_delimiter TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMP(0) NULL,
|
||||
updated_at TIMESTAMP(0) NULL
|
||||
)`,
|
||||
`INSERT INTO golem15_seo_settings (id, query_params, created_at, updated_at) VALUES (1, '[
|
||||
{"name": "page", "kind": "content", "path": ""},
|
||||
{"name": "utm_*", "kind": "tracking", "path": ""},
|
||||
{"name": "fbclid", "kind": "tracking", "path": ""},
|
||||
{"name": "gclid", "kind": "tracking", "path": ""},
|
||||
{"name": "msclkid", "kind": "tracking", "path": ""},
|
||||
{"name": "sort", "kind": "filter", "path": ""}
|
||||
]'::jsonb, NOW(), NOW())`,
|
||||
} {
|
||||
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_settings`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createSettings...)
|
||||
}
|
||||
39
updates/202610270005_create_golem15_seo_rules.go
Normal file
39
updates/202610270005_create_golem15_seo_rules.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package updates
|
||||
|
||||
import (
|
||||
"github.com/go-gormigrate/gormigrate/v2"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// createRules creates golem15_seo_rules: per-URL SEO for exact addresses
|
||||
// and patterns (D-02), one rule per address and match.
|
||||
var createRules = []*gormigrate.Migration{
|
||||
{
|
||||
ID: "202610270005_create_golem15_seo_rules",
|
||||
Migrate: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`CREATE TABLE golem15_seo_rules (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
url TEXT NOT NULL,
|
||||
match TEXT NOT NULL DEFAULT 'exact',
|
||||
title TEXT NOT NULL DEFAULT '',
|
||||
description 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 '',
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMP(0) NULL,
|
||||
updated_at TIMESTAMP(0) NULL,
|
||||
CONSTRAINT golem15_seo_rules_url_match UNIQUE (url, match)
|
||||
)`).Error
|
||||
},
|
||||
Rollback: func(tx *gorm.DB) error {
|
||||
return tx.Exec(`DROP TABLE IF EXISTS golem15_seo_rules`).Error
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(createRules...)
|
||||
}
|
||||
Reference in New Issue
Block a user