"""initial schema Revision ID: 251f3f69d89e Revises: Create Date: 2026-05-18 20:42:23.832037 """ from typing import Sequence, Union from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision: str = '251f3f69d89e' down_revision: Union[str, Sequence[str], None] = None branch_labels: Union[str, Sequence[str], None] = None depends_on: Union[str, Sequence[str], None] = None def upgrade() -> None: """Upgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.create_table('tags', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=100), nullable=False), sa.Column('color', sa.String(length=7), nullable=True), sa.Column('description', sa.Text(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_tags_name'), 'tags', ['name'], unique=True) op.create_table('users', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('username', sa.String(length=100), nullable=False), sa.Column('email', sa.String(length=255), nullable=False), sa.Column('password_hash', sa.String(length=255), nullable=False), sa.Column('role', sa.String(length=20), nullable=False), sa.Column('is_active', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True) op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True) op.create_table('api_keys', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('user_id', sa.String(length=36), nullable=False), sa.Column('key_hash', sa.String(length=255), nullable=False), sa.Column('name', sa.String(length=100), nullable=True), sa.Column('expires_at', sa.DateTime(), nullable=True), sa.Column('is_active', sa.Boolean(), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('key_hash') ) op.create_index(op.f('ix_api_keys_user_id'), 'api_keys', ['user_id'], unique=False) op.create_table('audit_log', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('user_id', sa.String(length=36), nullable=True), sa.Column('action', sa.String(length=100), nullable=False), sa.Column('entity_type', sa.String(length=50), nullable=False), sa.Column('entity_id', sa.String(length=36), nullable=True), sa.Column('old_value', sa.JSON(), nullable=True), sa.Column('new_value', sa.JSON(), nullable=True), sa.Column('ip_address', sa.String(length=45), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='SET NULL'), sa.PrimaryKeyConstraint('id') ) op.create_table('collections', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=200), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('query_type', sa.String(length=20), nullable=False), sa.Column('query_expression', sa.JSON(), nullable=True), sa.Column('is_public', sa.Boolean(), nullable=True), sa.Column('created_by', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.ForeignKeyConstraint(['created_by'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_table('links', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('url', sa.String(length=2048), nullable=False), sa.Column('title', sa.String(length=255), nullable=False), sa.Column('description', sa.Text(), nullable=True), sa.Column('notes', sa.Text(), nullable=True), sa.Column('tags', sa.JSON(), nullable=True), sa.Column('favicon_url', sa.String(length=512), nullable=True), sa.Column('path', sa.String(length=512), nullable=True), sa.Column('visit_count', sa.Integer(), nullable=True), sa.Column('is_bookmarked', sa.Boolean(), nullable=True), sa.Column('source_set_id', sa.String(length=36), nullable=True), sa.Column('user_id', sa.String(length=36), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.ForeignKeyConstraint(['source_set_id'], ['links.id'], ), sa.ForeignKeyConstraint(['user_id'], ['users.id'], ), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_links_url'), 'links', ['url'], unique=False) op.create_table('collection_bookmarks', sa.Column('collection_id', sa.String(length=36), nullable=False), sa.Column('bookmark_id', sa.String(length=36), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.Column('updated_at', sa.DateTime(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False), sa.ForeignKeyConstraint(['bookmark_id'], ['links.id'], ), sa.ForeignKeyConstraint(['collection_id'], ['collections.id'], ), sa.PrimaryKeyConstraint('collection_id', 'bookmark_id') ) # ### end Alembic commands ### def downgrade() -> None: """Downgrade schema.""" # ### commands auto generated by Alembic - please adjust! ### op.drop_table('collection_bookmarks') op.drop_index(op.f('ix_links_url'), table_name='links') op.drop_table('links') op.drop_table('collections') op.drop_table('audit_log') op.drop_index(op.f('ix_api_keys_user_id'), table_name='api_keys') op.drop_table('api_keys') op.drop_index(op.f('ix_users_username'), table_name='users') op.drop_index(op.f('ix_users_email'), table_name='users') op.drop_table('users') op.drop_index(op.f('ix_tags_name'), table_name='tags') op.drop_table('tags') # ### end Alembic commands ###