mirror of
https://github.com/knadh/listmonk.git
synced 2025-03-03 01:34:30 +08:00
- Add materialized views for list -> subscriber counts, dashboard chart, and dashboard aggregate stats that slow down significantly on large databases (with millions or tens of millions of subscribers). These slow queries involve full table scan COUNTS(). - Add a toggle to enable caching slow results in Settings -> Performance. - Add support for setting a cron string that crons and periodically refreshes aggregated stats in materialized views. Closes #1019.
43 lines
1.2 KiB
Go
43 lines
1.2 KiB
Go
package migrations
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
"github.com/knadh/koanf/v2"
|
|
"github.com/knadh/stuffbin"
|
|
)
|
|
|
|
// V2_2_0 performs the DB migrations for v.2.3.0.
|
|
func V2_3_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf, lo *log.Logger) error {
|
|
if _, err := db.Exec(`ALTER TABLE media ADD COLUMN IF NOT EXISTS "meta" JSONB NOT NULL DEFAULT '{}'`); err != nil {
|
|
return err
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Insert new preference settings.
|
|
if _, err := db.Exec(`
|
|
INSERT INTO settings (key, value) VALUES
|
|
('app.site_name', '"Mailing list"'),
|
|
('app.enable_public_archive', 'true'),
|
|
('privacy.allow_preferences', 'false')
|
|
ON CONFLICT DO NOTHING;
|
|
`); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|