"""Add notebook_id to queries table

Revision ID: 8bb58de0936a
Revises: add_schema_cache_001
Create Date: 2025-09-04 19:36:14.142879

"""

from alembic import op
import sqlalchemy as sa



# revision identifiers, used by Alembic.
revision = '8bb58de0936a'
down_revision = 'add_schema_cache_001'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('queries',
    sa.Column('id', sa.String(length=36), nullable=False),
    sa.Column('name', sa.Text(), nullable=False),
    sa.Column('query', sa.Text(), nullable=False),
    sa.Column('output_schema', sa.Text(), nullable=False),
    sa.Column('connection_id', sa.String(length=36), nullable=False),
    sa.Column('notebook_id', sa.String(length=36), nullable=False),
    sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.Column('updated_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.ForeignKeyConstraint(['connection_id'], ['connections.id'], name=op.f('fk_queries_connection_id_connections'), ondelete='CASCADE'),
    sa.ForeignKeyConstraint(['notebook_id'], ['notebooks.id'], name=op.f('fk_queries_notebook_id_notebooks'), ondelete='CASCADE'),
    sa.PrimaryKeyConstraint('id', name=op.f('pk_queries'))
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('queries')
    # ### end Alembic commands ###

