"""create_config_folders_table

Revision ID: 8ed7dd80973d
Revises: 398082499c30
Create Date: 2026-05-22 18:38:22.133696
"""

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

# revision identifiers, used by Alembic.
revision = '8ed7dd80973d'
down_revision = '398082499c30'
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        'config_folders',
        sa.Column('id', postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text('gen_random_uuid()')),
        sa.Column('user_id', postgresql.UUID(as_uuid=True), sa.ForeignKey('users.id', ondelete='CASCADE'), nullable=False),
        sa.Column('name', sa.String(255), nullable=False),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('mount_path', sa.String(1024), nullable=False),
        sa.Column('files', postgresql.JSONB(astext_type=sa.Text()), nullable=False, server_default='{}'),
        sa.Column('project_overrides', postgresql.JSONB(astext_type=sa.Text()), nullable=True, server_default='{}'),
        sa.Column('is_active', sa.Boolean(), nullable=False, server_default='true'),
        sa.Column('created_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('NOW()')),
        sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False, server_default=sa.text('NOW()')),
        sa.UniqueConstraint('user_id', 'name', name='uq_config_folders_user_name')
    )
    
    # Add index on user_id for filtering
    op.create_index('idx_config_folders_user', 'config_folders', ['user_id'])


def downgrade() -> None:
    # Drop index
    op.drop_index('idx_config_folders_user', table_name='config_folders')
    
    # Drop table
    op.drop_table('config_folders')
