Implemented alembic migrations, added cursors closing task.

This commit is contained in:
2025-02-25 23:37:55 +03:00
parent 836ce1dc82
commit 1abc225923
17 changed files with 746 additions and 101 deletions

View File

@@ -0,0 +1,32 @@
"""Added pool size config to the connection model.
Revision ID: 1c62ff091f5c
Revises: 6eb236240aec
Create Date: 2025-02-25 19:24:21.712856
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '1c62ff091f5c'
down_revision: Union[str, None] = '6eb236240aec'
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.add_column('connections', sa.Column('pool_minsize', sa.Integer(), nullable=False, server_default="5"))
op.add_column('connections', sa.Column('pool_maxsize', sa.Integer(), nullable=False, server_default="10"))
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('connections', 'pool_maxsize')
op.drop_column('connections', 'pool_minsize')
# ### end Alembic commands ###

View File

@@ -0,0 +1,75 @@
"""Initial migration.
Revision ID: 6eb236240aec
Revises:
Create Date: 2025-02-25 19:18:03.125433
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '6eb236240aec'
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('users',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('role', sa.Enum('admin', 'user', name='userrole'), nullable=False),
sa.Column('api_key', sa.String(), nullable=False),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('api_key')
)
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
op.create_table('connections',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('db_name', sa.String(), nullable=False),
sa.Column('type', sa.Enum('mysql', 'postgresql', name='connectiontypes'), nullable=False),
sa.Column('host', sa.String(), nullable=True),
sa.Column('port', sa.Integer(), nullable=True),
sa.Column('username', sa.String(), nullable=True),
sa.Column('password', sa.String(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_connections_id'), 'connections', ['id'], unique=False)
op.create_table('queries',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.Column('owner_id', sa.Integer(), nullable=True),
sa.Column('table_name', sa.String(), nullable=False),
sa.Column('columns', sa.JSON(), nullable=False),
sa.Column('filters', sa.JSON(), nullable=True),
sa.Column('sort_by', sa.JSON(), nullable=True),
sa.Column('limit', sa.Integer(), nullable=True),
sa.Column('offset', sa.Integer(), nullable=True),
sa.Column('sql', sa.String(), nullable=False),
sa.Column('params', sa.JSON(), nullable=False),
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_queries_id'), 'queries', ['id'], unique=False)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_queries_id'), table_name='queries')
op.drop_table('queries')
op.drop_index(op.f('ix_connections_id'), table_name='connections')
op.drop_table('connections')
op.drop_index(op.f('ix_users_username'), table_name='users')
op.drop_index(op.f('ix_users_id'), table_name='users')
op.drop_table('users')
# ### end Alembic commands ###