"""indexing created_at updated_at

Revision ID: 9aae9138c4ef
Revises: 91c94250232a
Create Date: 2025-03-04 22:54:14.895030

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel
import sqlmodel.sql.sqltypes


# revision identifiers, used by Alembic.
revision: str = '9aae9138c4ef'
down_revision: Union[str, None] = '91c94250232a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('attachments', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_attachments_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_attachments_updated_at'), ['updated_at'], unique=False)

    with op.batch_alter_table('entries', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_entries_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_entries_updated_at'), ['updated_at'], unique=False)

    with op.batch_alter_table('permissions', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_permissions_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_permissions_updated_at'), ['updated_at'], unique=False)

    with op.batch_alter_table('roles', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_roles_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_roles_updated_at'), ['updated_at'], unique=False)

    with op.batch_alter_table('spaces', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_spaces_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_spaces_updated_at'), ['updated_at'], unique=False)

    with op.batch_alter_table('users', schema=None) as batch_op:
        batch_op.create_index(batch_op.f('ix_users_created_at'), ['created_at'], unique=False)
        batch_op.create_index(batch_op.f('ix_users_updated_at'), ['updated_at'], unique=False)
        batch_op.create_foreign_key(None, 'users', ['owner_shortname'], ['shortname'])

    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    with op.batch_alter_table('users', schema=None) as batch_op:
        batch_op.drop_constraint(None, type_='foreignkey')
        batch_op.drop_index(batch_op.f('ix_users_updated_at'))
        batch_op.drop_index(batch_op.f('ix_users_created_at'))

    with op.batch_alter_table('spaces', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_spaces_updated_at'))
        batch_op.drop_index(batch_op.f('ix_spaces_created_at'))

    with op.batch_alter_table('roles', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_roles_updated_at'))
        batch_op.drop_index(batch_op.f('ix_roles_created_at'))

    with op.batch_alter_table('permissions', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_permissions_updated_at'))
        batch_op.drop_index(batch_op.f('ix_permissions_created_at'))

    with op.batch_alter_table('entries', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_entries_updated_at'))
        batch_op.drop_index(batch_op.f('ix_entries_created_at'))

    with op.batch_alter_table('attachments', schema=None) as batch_op:
        batch_op.drop_index(batch_op.f('ix_attachments_updated_at'))
        batch_op.drop_index(batch_op.f('ix_attachments_created_at'))

    # ### end Alembic commands ###
