"""add_paperless_username_password_fields

Revision ID: e6522bf55699
Revises: b37b4e5cfd0b
Create Date: 2025-07-31 17:04:38.316250

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'e6522bf55699'
down_revision = 'b37b4e5cfd0b'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('entity_files', 'storage_backend',
               existing_type=sa.VARCHAR(length=20),
               server_default=None,
               existing_nullable=False)
    op.alter_column('entity_files', 'sync_status',
               existing_type=sa.VARCHAR(length=20),
               server_default=None,
               existing_nullable=False)
    op.add_column('user_preferences', sa.Column('paperless_username_encrypted', sa.Text(), nullable=True))
    op.add_column('user_preferences', sa.Column('paperless_password_encrypted', sa.Text(), nullable=True))
    op.alter_column('user_preferences', 'paperless_enabled',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('user_preferences', 'default_storage_backend',
               existing_type=sa.VARCHAR(length=20),
               server_default=None,
               existing_nullable=False)
    op.alter_column('user_preferences', 'paperless_auto_sync',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    op.alter_column('user_preferences', 'paperless_sync_tags',
               existing_type=sa.BOOLEAN(),
               server_default=None,
               existing_nullable=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('user_preferences', 'paperless_sync_tags',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('true'),
               existing_nullable=False)
    op.alter_column('user_preferences', 'paperless_auto_sync',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.alter_column('user_preferences', 'default_storage_backend',
               existing_type=sa.VARCHAR(length=20),
               server_default=sa.text("'local'::character varying"),
               existing_nullable=False)
    op.alter_column('user_preferences', 'paperless_enabled',
               existing_type=sa.BOOLEAN(),
               server_default=sa.text('false'),
               existing_nullable=False)
    op.drop_column('user_preferences', 'paperless_password_encrypted')
    op.drop_column('user_preferences', 'paperless_username_encrypted')
    op.alter_column('entity_files', 'sync_status',
               existing_type=sa.VARCHAR(length=20),
               server_default=sa.text("'synced'::character varying"),
               existing_nullable=False)
    op.alter_column('entity_files', 'storage_backend',
               existing_type=sa.VARCHAR(length=20),
               server_default=sa.text("'local'::character varying"),
               existing_nullable=False)
    # ### end Alembic commands ###
