mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
migration: add user profile columns
This commit is contained in:
parent
596cef1952
commit
2e2534ccac
1 changed files with 72 additions and 0 deletions
|
|
@ -0,0 +1,72 @@
|
|||
"""Add display_name and avatar_url columns to user table
|
||||
|
||||
This migration adds:
|
||||
- display_name column for user's full name from OAuth
|
||||
- avatar_url column for user's profile picture URL from OAuth
|
||||
|
||||
Revision ID: 62
|
||||
Revises: 61
|
||||
"""
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "62"
|
||||
down_revision: str | None = "61"
|
||||
branch_labels: str | Sequence[str] | None = None
|
||||
depends_on: str | Sequence[str] | None = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Add display_name and avatar_url columns to user table."""
|
||||
|
||||
# Add display_name column (nullable for existing users)
|
||||
op.execute(
|
||||
"""
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'user' AND column_name = 'display_name'
|
||||
) THEN
|
||||
ALTER TABLE "user"
|
||||
ADD COLUMN display_name VARCHAR;
|
||||
END IF;
|
||||
END$$;
|
||||
"""
|
||||
)
|
||||
|
||||
# Add avatar_url column (nullable for existing users)
|
||||
op.execute(
|
||||
"""
|
||||
DO $$
|
||||
BEGIN
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'user' AND column_name = 'avatar_url'
|
||||
) THEN
|
||||
ALTER TABLE "user"
|
||||
ADD COLUMN avatar_url VARCHAR;
|
||||
END IF;
|
||||
END$$;
|
||||
"""
|
||||
)
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Remove display_name and avatar_url columns from user table."""
|
||||
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE "user"
|
||||
DROP COLUMN IF EXISTS avatar_url;
|
||||
"""
|
||||
)
|
||||
op.execute(
|
||||
"""
|
||||
ALTER TABLE "user"
|
||||
DROP COLUMN IF EXISTS display_name;
|
||||
"""
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue