"""User project_dirs and UserGroup viewer paths

Revision ID: 7910eed4cf97
Revises: bc0e8b3327a7
Create Date: 2025-11-27 16:02:51.824653

"""

import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "7910eed4cf97"
down_revision = "bc0e8b3327a7"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("user_oauth", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "project_dirs",
                postgresql.ARRAY(sa.String()),
                server_default="{}",
                nullable=False,
            )
        )
        batch_op.alter_column(
            "project_dir", existing_type=sa.VARCHAR(), nullable=True
        )

    with op.batch_alter_table("usergroup", schema=None) as batch_op:
        batch_op.drop_column("viewer_paths")

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table("usergroup", schema=None) as batch_op:
        batch_op.add_column(
            sa.Column(
                "viewer_paths",
                postgresql.JSONB(astext_type=sa.Text()),
                server_default=sa.text("'[]'::json"),
                autoincrement=False,
                nullable=False,
            )
        )

    with op.batch_alter_table("user_oauth", schema=None) as batch_op:
        batch_op.alter_column(
            "project_dir", existing_type=sa.VARCHAR(), nullable=False
        )
        batch_op.drop_column("project_dirs")

    # ### end Alembic commands ###
