"""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")