"""initial

Revision ID: 74288ccbd3b5
Revises: 
Create Date: 2024-11-25 13:53:25.928935

"""
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 = '74288ccbd3b5'
down_revision: Union[str, None] = None
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! ###
    op.create_table('activesessions',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('token', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname')
    )
    op.create_table('attachments',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('media', sa.LargeBinary(), nullable=True),
    sa.Column('body', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('state', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('entries',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('state', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('is_open', sa.Boolean(), nullable=True),
    sa.Column('reporter', sa.JSON(), nullable=True),
    sa.Column('workflow_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('collaborators', sa.JSON(), nullable=True),
    sa.Column('resolution_reason', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('failedloginattempts',
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('attempt_count', sa.Integer(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('uuid')
    )
    op.create_table('histories',
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('request_headers', sa.JSON(), nullable=False),
    sa.Column('diff', sa.JSON(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.PrimaryKeyConstraint('uuid')
    )
    op.create_table('invitations',
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('invitation_token', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('invitation_value', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('uuid')
    )
    op.create_table('locks',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('permissions',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpaths', sa.JSON(), nullable=False),
    sa.Column('resource_types', sa.JSON(), nullable=False),
    sa.Column('actions', sa.JSON(), nullable=False),
    sa.Column('conditions', sa.JSON(), nullable=False),
    sa.Column('restricted_fields', sa.JSON(), nullable=True),
    sa.Column('allowed_fields_values', sa.JSON(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('roles',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('permissions', sa.JSON(), nullable=False),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('sessions',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('token', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname')
    )
    op.create_table('spaces',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('root_registration_signature', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('primary_website', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('indexing_enabled', sa.Boolean(), nullable=False),
    sa.Column('capture_misses', sa.Boolean(), nullable=False),
    sa.Column('check_health', sa.Boolean(), nullable=False),
    sa.Column('languages', sa.JSON(), nullable=False),
    sa.Column('icon', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('mirrors', sa.JSON(), nullable=True),
    sa.Column('hide_folders', sa.JSON(), nullable=True),
    sa.Column('hide_space', sa.Boolean(), nullable=True),
    sa.Column('active_plugins', sa.JSON(), nullable=True),
    sa.Column('ordinal', sa.Integer(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    op.create_table('urlshorts',
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('token_uuid', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('url', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('timestamp', sa.DateTime(), nullable=False),
    sa.PrimaryKeyConstraint('uuid')
    )
    op.create_table('users',
    sa.Column('shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('space_name', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('subpath', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('uuid', sa.Uuid(), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('slug', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('displayname', sa.JSON(), nullable=True),
    sa.Column('description', sa.JSON(), nullable=True),
    sa.Column('tags', sa.JSON(), nullable=False),
    sa.Column('created_at', sa.DateTime(), nullable=True),
    sa.Column('updated_at', sa.DateTime(), nullable=True),
    sa.Column('owner_shortname', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('payload', sa.JSON(), nullable=True),
    sa.Column('resource_type', sqlmodel.sql.sqltypes.AutoString(), nullable=False),
    sa.Column('password', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('roles', sa.JSON(), nullable=False),
    sa.Column('groups', sa.JSON(), nullable=False),
    sa.Column('acl', sa.JSON(), nullable=True),
    sa.Column('relationships', sa.JSON(), nullable=True),
    sa.Column('type', sa.Enum('web', 'mobile', 'bot', name='usertype'), nullable=False),
    sa.Column('language', sa.Enum('ar', 'en', 'ku', 'fr', 'tr', name='language'), nullable=False),
    sa.Column('email', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('msisdn', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('is_email_verified', sa.Boolean(), nullable=False),
    sa.Column('is_msisdn_verified', sa.Boolean(), nullable=False),
    sa.Column('force_password_change', sa.Boolean(), nullable=False),
    sa.Column('firebase_token', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('google_id', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('facebook_id', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.Column('social_avatar_url', sqlmodel.sql.sqltypes.AutoString(), nullable=True),
    sa.PrimaryKeyConstraint('uuid'),
    sa.UniqueConstraint('shortname', 'space_name', 'subpath')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('users')
    op.drop_table('urlshorts')
    op.drop_table('spaces')
    op.drop_table('sessions')
    op.drop_table('roles')
    op.drop_table('permissions')
    op.drop_table('locks')
    op.drop_table('invitations')
    op.drop_table('histories')
    op.drop_table('failedloginattempts')
    op.drop_table('entries')
    op.drop_table('attachments')
    op.drop_table('activesessions')
    # ### end Alembic commands ###
