2026-09-03 15:58:13 -05:00
|
|
|
"""Peewee migrations -- 038_create_notices.py.
|
|
|
|
|
|
|
|
|
|
Creates the two notice tables: active notices, and per-kind lifetime counts.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import peewee as pw
|
|
|
|
|
|
|
|
|
|
SQL = pw.SQL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def migrate(migrator, database, fake=False, **kwargs):
|
|
|
|
|
migrator.sql(
|
|
|
|
|
'CREATE TABLE IF NOT EXISTS "notice" ('
|
|
|
|
|
'"id" VARCHAR(150) NOT NULL PRIMARY KEY, '
|
|
|
|
|
'"kind" VARCHAR(50) NOT NULL, '
|
|
|
|
|
'"scope" VARCHAR(100), '
|
|
|
|
|
'"params" TEXT NOT NULL, '
|
|
|
|
|
'"first_seen" DATETIME NOT NULL, '
|
|
|
|
|
'"last_seen" DATETIME NOT NULL, '
|
|
|
|
|
'"count" INTEGER NOT NULL, '
|
2026-09-24 16:39:18 -05:00
|
|
|
'"acknowledged_at" DATETIME, '
|
|
|
|
|
'"muted_at" DATETIME)'
|
2026-09-03 15:58:13 -05:00
|
|
|
)
|
|
|
|
|
migrator.sql('CREATE INDEX IF NOT EXISTS "notice_kind" ON "notice" ("kind")')
|
|
|
|
|
migrator.sql(
|
|
|
|
|
'CREATE TABLE IF NOT EXISTS "noticestats" ('
|
|
|
|
|
'"kind" VARCHAR(50) NOT NULL PRIMARY KEY, '
|
|
|
|
|
'"occurrences" INTEGER NOT NULL, '
|
2026-09-24 16:39:18 -05:00
|
|
|
'"acknowledgements" INTEGER NOT NULL, '
|
|
|
|
|
'"mutes" INTEGER NOT NULL, '
|
2026-09-03 15:58:13 -05:00
|
|
|
'"first_seen" DATETIME NOT NULL, '
|
|
|
|
|
'"last_seen" DATETIME NOT NULL, '
|
|
|
|
|
'"reported_occurrences" INTEGER NOT NULL DEFAULT 0, '
|
2026-09-24 16:39:18 -05:00
|
|
|
'"reported_acknowledgements" INTEGER NOT NULL DEFAULT 0, '
|
|
|
|
|
'"reported_mutes" INTEGER NOT NULL DEFAULT 0)'
|
2026-09-03 15:58:13 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rollback(migrator, database, fake=False, **kwargs):
|
|
|
|
|
migrator.sql('DROP TABLE IF EXISTS "notice"')
|
|
|
|
|
migrator.sql('DROP TABLE IF EXISTS "noticestats"')
|