a0bea36041
- Remove extended columns (repo_id, issue_id, pull_request_id, channel_id, message_id, target_type, target_id, action_url, priority, metadata, deleted_at) from CREATE TABLE in 001_init.sql - Add migration 013_notification_extra_columns.sql that uses ALTER TABLE ADD COLUMN IF NOT EXISTS for all extended columns - Move extended column indexes to the new migration - Ensures compatibility with databases that already have a basic notification table from a previous schema version
25 lines
1.9 KiB
SQL
25 lines
1.9 KiB
SQL
-- Migration: 013_notification_extra_columns.sql
|
|
-- Add extended columns to notification table for full feature support.
|
|
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS repo_id UUID NULL REFERENCES repo(id) ON DELETE CASCADE;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS issue_id UUID NULL REFERENCES issue(id) ON DELETE CASCADE;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS pull_request_id UUID NULL REFERENCES pull_request(id) ON DELETE CASCADE;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS channel_id UUID NULL REFERENCES channel(id) ON DELETE CASCADE;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS message_id UUID NULL REFERENCES message(id) ON DELETE CASCADE;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS target_type TEXT NULL;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS target_id UUID NULL;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS action_url TEXT NULL;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS priority TEXT NOT NULL DEFAULT 'normal';
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS metadata JSONB NULL;
|
|
ALTER TABLE notification ADD COLUMN IF NOT EXISTS deleted_at TIMESTAMPTZ NULL;
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_notification_repo_id ON notification (repo_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_issue_id ON notification (issue_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_pull_request_id ON notification (pull_request_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_channel_id ON notification (channel_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_message_id ON notification (message_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_target_id ON notification (target_id);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_repo_created ON notification (repo_id, created_at DESC);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_ws_created ON notification (workspace_id, created_at DESC);
|
|
CREATE INDEX IF NOT EXISTS idx_notification_deleted ON notification (deleted_at) WHERE deleted_at IS NOT NULL;
|