06/23 Implement broadcast function for admin

This commit is contained in:
Nguyen Ngo
2026-06-23 18:55:53 -04:00
parent ed74e5064c
commit 056690e6da
7 changed files with 366 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
"""phase29 — broadcasts table for admin push notifications to iOS
Adds the `broadcasts` table. Each row records an admin-composed message,
the roles it targeted, who sent it, and how many Notification rows were
created. The Notification rows themselves are written at send-time using
the existing notify() utility — no schema changes to that table are needed.
"""
from alembic import op
import sqlalchemy as sa
revision = 'phase29_broadcasts'
down_revision = 'phase28_fix_inspection_notify'
branch_labels = None
depends_on = None
def upgrade():
op.execute("""
CREATE TABLE IF NOT EXISTS broadcasts (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
body TEXT NOT NULL,
target_roles JSON NOT NULL,
sent_by_id INT NULL,
sent_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
recipient_count INT NOT NULL DEFAULT 0,
CONSTRAINT fk_broadcast_sender
FOREIGN KEY (sent_by_id) REFERENCES users(id)
ON DELETE SET NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
""")
def downgrade():
op.execute("DROP TABLE IF EXISTS broadcasts")