2022-10-03 01:34:51 +08:00
|
|
|
package migrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jmoiron/sqlx"
|
2023-04-10 15:15:25 +08:00
|
|
|
"github.com/knadh/koanf/v2"
|
2022-10-03 01:34:51 +08:00
|
|
|
"github.com/knadh/stuffbin"
|
|
|
|
)
|
|
|
|
|
|
|
|
// V2_2_0 performs the DB migrations for v.2.2.0.
|
|
|
|
func V2_3_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error {
|
|
|
|
if _, err := db.Exec(`ALTER TABLE media ADD COLUMN IF NOT EXISTS "meta" JSONB NOT NULL DEFAULT '{}'`); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-01 23:29:21 +08:00
|
|
|
// Add `description` field to lists.
|
|
|
|
if _, err := db.Exec(`ALTER TABLE lists ADD COLUMN IF NOT EXISTS "description" TEXT NOT NULL DEFAULT ''`); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-03 13:37:26 +08:00
|
|
|
// Add archive publishing field to campaigns.
|
|
|
|
if _, err := db.Exec(`ALTER TABLE campaigns
|
|
|
|
ADD COLUMN IF NOT EXISTS archive BOOLEAN NOT NULL DEFAULT false,
|
|
|
|
ADD COLUMN IF NOT EXISTS archive_meta JSONB NOT NULL DEFAULT '{}',
|
|
|
|
ADD COLUMN IF NOT EXISTS archive_template_id INTEGER REFERENCES templates(id) ON DELETE SET DEFAULT DEFAULT 1
|
|
|
|
`); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-01 23:29:21 +08:00
|
|
|
// Insert new preference settings.
|
2022-10-19 00:14:57 +08:00
|
|
|
if _, err := db.Exec(`
|
|
|
|
INSERT INTO settings (key, value) VALUES
|
2022-11-10 23:49:53 +08:00
|
|
|
('app.site_name', '"Mailing list"'),
|
2022-11-11 00:54:15 +08:00
|
|
|
('app.enable_public_archive', 'true'),
|
2022-10-19 00:14:57 +08:00
|
|
|
('privacy.allow_preferences', 'false')
|
|
|
|
ON CONFLICT DO NOTHING;
|
|
|
|
`); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-10-03 01:34:51 +08:00
|
|
|
return nil
|
|
|
|
}
|