mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 01:06:23 +02:00
migration: add author_id to messages
This commit is contained in:
parent
d89bcf13c3
commit
efcc394b0c
1 changed files with 47 additions and 0 deletions
|
|
@ -0,0 +1,47 @@
|
|||
"""Add author_id column to new_chat_messages table
|
||||
|
||||
Revision ID: 63
|
||||
Revises: 62
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision: str = "63"
|
||||
down_revision: str | None = "62"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add author_id column to new_chat_messages table."""
|
||||
op.execute(
|
||||
"""
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'new_chat_messages' AND column_name = 'author_id'
|
||||
) THEN
|
||||
ALTER TABLE new_chat_messages
|
||||
ADD COLUMN author_id UUID REFERENCES "user"(id) ON DELETE SET NULL;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS ix_new_chat_messages_author_id
|
||||
ON new_chat_messages(author_id);
|
||||
END IF;
|
||||
END$$;
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Remove author_id column from new_chat_messages table."""
|
||||
op.execute(
|
||||
"""
|
||||
DROP INDEX IF EXISTS ix_new_chat_messages_author_id;
|
||||
ALTER TABLE new_chat_messages
|
||||
DROP COLUMN IF EXISTS author_id;
|
||||
"""
|
||||
)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue