db change

This commit is contained in:
2026-08-29 13:04:41 +03:00
parent 443d40d7b6
commit 198506f062
21 changed files with 455 additions and 555 deletions
+5 -1
View File
@@ -39,7 +39,11 @@ class LoggingMiddleware(BaseHTTPMiddleware):
try:
body = json.loads(body_bytes)
body=body.get("detail", None)
if not isinstance(body, bool):
body=body.get("detail", None)
else:
body=None
except (json.JSONDecodeError, TypeError):
body = None
+1 -1
View File
@@ -6,7 +6,7 @@ from sqlalchemy import create_engine, pool
from src.models.database_models import Model
from src.models.database_models.model import engine
sync_url = engine.url.render_as_string(hide_password=False).replace("+aiosqlite", "")
sync_url = engine.url.render_as_string(hide_password=False).replace("+asyncpg", "")
sync_engine = create_engine(sync_url, poolclass=pool.NullPool)
# this is the Alembic Config object, which provides
-32
View File
@@ -1,32 +0,0 @@
"""empty message
Revision ID: 23dd6d3efe4b
Revises: 2f92088cdce4
Create Date: 2026-07-23 13:05:12.553687
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '23dd6d3efe4b'
down_revision: Union[str, Sequence[str], None] = '2f92088cdce4'
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! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
-32
View File
@@ -1,32 +0,0 @@
"""empty message
Revision ID: 2f92088cdce4
Revises: 75074097a2a3
Create Date: 2026-07-23 11:05:02.409697
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '2f92088cdce4'
down_revision: Union[str, Sequence[str], None] = '75074097a2a3'
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! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
-50
View File
@@ -1,50 +0,0 @@
"""empty message
Revision ID: 385d4efec15f
Revises: 23dd6d3efe4b
Create Date: 2026-07-23 15:03:33.582896
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '385d4efec15f'
down_revision: Union[str, Sequence[str], None] = '23dd6d3efe4b'
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! ###
with op.batch_alter_table('refresh_tokens', schema=None) as batch_op:
batch_op.alter_column('id',
existing_type=sa.INTEGER(),
type_=sa.Uuid(),
existing_nullable=False)
batch_op.alter_column('replaced_by',
existing_type=sa.INTEGER(),
type_=sa.Uuid(),
existing_nullable=True)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('refresh_tokens', schema=None) as batch_op:
batch_op.alter_column('replaced_by',
existing_type=sa.Uuid(),
type_=sa.INTEGER(),
existing_nullable=True)
batch_op.alter_column('id',
existing_type=sa.Uuid(),
type_=sa.INTEGER(),
existing_nullable=False)
# ### end Alembic commands ###
-69
View File
@@ -1,69 +0,0 @@
"""empty message
Revision ID: 439a77f8a4d4
Revises: 5e60c8fbc553
Create Date: 2026-07-22 15:19:15.853280
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '439a77f8a4d4'
down_revision: Union[str, Sequence[str], None] = '5e60c8fbc553'
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('markets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_markets')),
sa.UniqueConstraint('name', name=op.f('uq_markets_name'))
)
with op.batch_alter_table('markets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_markets_id'), ['id'], unique=False)
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.add_column(sa.Column('doc_id', sa.Uuid(), nullable=False))
batch_op.add_column(sa.Column('uploaded_at', sa.TIMESTAMP(), nullable=False))
batch_op.add_column(sa.Column('doc_date', sa.TIMESTAMP(), nullable=False))
batch_op.add_column(sa.Column('status', sa.String(length=64), nullable=False))
batch_op.add_column(sa.Column('user_id', sa.Uuid(), nullable=False))
batch_op.add_column(sa.Column('market_id', sa.Integer(), nullable=False))
batch_op.create_index(batch_op.f('ix_reports_market_id'), ['market_id'], unique=False)
batch_op.create_index(batch_op.f('ix_reports_user_id'), ['user_id'], unique=False)
batch_op.create_unique_constraint(batch_op.f('uq_reports_doc_id'), ['doc_id'])
batch_op.create_foreign_key(batch_op.f('fk_reports_user_id_users'), 'users', ['user_id'], ['id'], ondelete='CASCADE')
batch_op.create_foreign_key(batch_op.f('fk_reports_market_id_markets'), 'markets', ['market_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('fk_reports_market_id_markets'), type_='foreignkey')
batch_op.drop_constraint(batch_op.f('fk_reports_user_id_users'), type_='foreignkey')
batch_op.drop_constraint(batch_op.f('uq_reports_doc_id'), type_='unique')
batch_op.drop_index(batch_op.f('ix_reports_user_id'))
batch_op.drop_index(batch_op.f('ix_reports_market_id'))
batch_op.drop_column('market_id')
batch_op.drop_column('user_id')
batch_op.drop_column('status')
batch_op.drop_column('doc_date')
batch_op.drop_column('uploaded_at')
batch_op.drop_column('doc_id')
with op.batch_alter_table('markets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_markets_id'))
op.drop_table('markets')
# ### end Alembic commands ###
-32
View File
@@ -1,32 +0,0 @@
"""empty message
Revision ID: 74814eb1b7f8
Revises: 8c136ff14180
Create Date: 2026-07-23 21:06:37.254211
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '74814eb1b7f8'
down_revision: Union[str, Sequence[str], None] = '8c136ff14180'
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! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
-103
View File
@@ -1,103 +0,0 @@
"""empty message
Revision ID: 75074097a2a3
Revises: 8c300c4d43ea
Create Date: 2026-07-22 16:11:08.077455
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '75074097a2a3'
down_revision: Union[str, Sequence[str], None] = '8c300c4d43ea'
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('accountant_settings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.Column('database_key', sa.Uuid(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_accountant_settings')),
sa.UniqueConstraint('database_key', name=op.f('uq_accountant_settings_database_key'))
)
with op.batch_alter_table('accountant_settings', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_accountant_settings_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_accountant_settings_name'), ['name'], unique=True)
op.create_table('doc_types',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_doc_types'))
)
with op.batch_alter_table('doc_types', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_doc_types_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_doc_types_name'), ['name'], unique=True)
op.create_table('fabric',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_fabric'))
)
with op.batch_alter_table('fabric', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_fabric_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_fabric_name'), ['name'], unique=True)
op.create_table('goods',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('article', sa.String(length=16), nullable=False),
sa.Column('price', sa.Numeric(precision=10, scale=2), nullable=False),
sa.Column('tnvd', sa.Integer(), nullable=False),
sa.Column('doc_type_id', sa.Integer(), nullable=False),
sa.Column('fabric_id', sa.Integer(), nullable=False),
sa.Column('status', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['doc_type_id'], ['doc_types.id'], name=op.f('fk_goods_doc_type_id_doc_types'), ondelete='CASCADE'),
sa.ForeignKeyConstraint(['fabric_id'], ['fabric.id'], name=op.f('fk_goods_fabric_id_fabric'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name=op.f('pk_goods'))
)
with op.batch_alter_table('goods', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_goods_article'), ['article'], unique=True)
batch_op.create_index(batch_op.f('ix_goods_doc_type_id'), ['doc_type_id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_fabric_id'), ['fabric_id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_price'), ['price'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_tnvd'), ['tnvd'], unique=True)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('goods', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_goods_tnvd'))
batch_op.drop_index(batch_op.f('ix_goods_price'))
batch_op.drop_index(batch_op.f('ix_goods_id'))
batch_op.drop_index(batch_op.f('ix_goods_fabric_id'))
batch_op.drop_index(batch_op.f('ix_goods_doc_type_id'))
batch_op.drop_index(batch_op.f('ix_goods_article'))
op.drop_table('goods')
with op.batch_alter_table('fabric', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_fabric_name'))
batch_op.drop_index(batch_op.f('ix_fabric_id'))
op.drop_table('fabric')
with op.batch_alter_table('doc_types', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_doc_types_name'))
batch_op.drop_index(batch_op.f('ix_doc_types_id'))
op.drop_table('doc_types')
with op.batch_alter_table('accountant_settings', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_accountant_settings_name'))
batch_op.drop_index(batch_op.f('ix_accountant_settings_id'))
op.drop_table('accountant_settings')
# ### end Alembic commands ###
-32
View File
@@ -1,32 +0,0 @@
"""empty message
Revision ID: 8c136ff14180
Revises: 385d4efec15f
Create Date: 2026-07-23 17:56:26.345954
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '8c136ff14180'
down_revision: Union[str, Sequence[str], None] = '385d4efec15f'
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! ###
pass
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
-40
View File
@@ -1,40 +0,0 @@
"""empty message
Revision ID: 8c300c4d43ea
Revises: 439a77f8a4d4
Create Date: 2026-07-22 15:20:34.871724
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '8c300c4d43ea'
down_revision: Union[str, Sequence[str], None] = '439a77f8a4d4'
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! ###
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.alter_column('uploaded_at',
existing_type=sa.TIMESTAMP(),
nullable=True)
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.alter_column('uploaded_at',
existing_type=sa.TIMESTAMP(),
nullable=False)
# ### end Alembic commands ###
-46
View File
@@ -1,46 +0,0 @@
"""empty message
Revision ID: ebe80cd28822
Revises: 74814eb1b7f8
Create Date: 2026-08-21 13:52:49.788041
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'ebe80cd28822'
down_revision: Union[str, Sequence[str], None] = '74814eb1b7f8'
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! ###
with op.batch_alter_table('user_direct_permissions', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('fk_user_direct_permissions_user_id_users'), type_='foreignkey')
batch_op.create_foreign_key(batch_op.f('fk_user_direct_permissions_user_id_users'), 'users', ['user_id'], ['id'], ondelete='CASCADE')
with op.batch_alter_table('user_group', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('fk_user_group_user_id_users'), type_='foreignkey')
batch_op.create_foreign_key(batch_op.f('fk_user_group_user_id_users'), 'users', ['user_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###
def downgrade() -> None:
"""Downgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('user_group', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('fk_user_group_user_id_users'), type_='foreignkey')
batch_op.create_foreign_key(batch_op.f('fk_user_group_user_id_users'), 'users', ['user_id'], ['id'])
with op.batch_alter_table('user_direct_permissions', schema=None) as batch_op:
batch_op.drop_constraint(batch_op.f('fk_user_direct_permissions_user_id_users'), type_='foreignkey')
batch_op.create_foreign_key(batch_op.f('fk_user_direct_permissions_user_id_users'), 'users', ['user_id'], ['id'])
# ### end Alembic commands ###
@@ -1,18 +1,18 @@
"""empty message
Revision ID: 5e60c8fbc553
Revision ID: f4018d3509eb
Revises:
Create Date: 2026-07-17 20:02:01.237457
Create Date: 2026-08-28 12:45:18.014540
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import text
# revision identifiers, used by Alembic.
revision: str = '5e60c8fbc553'
revision: str = 'f4018d3509eb'
down_revision: Union[str, Sequence[str], None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
@@ -21,6 +21,35 @@ depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
"""Upgrade schema."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('accountant_settings',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.Column('database_key', sa.Uuid(), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_accountant_settings')),
sa.UniqueConstraint('database_key', name=op.f('uq_accountant_settings_database_key'))
)
with op.batch_alter_table('accountant_settings', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_accountant_settings_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_accountant_settings_name'), ['name'], unique=True)
op.create_table('doc_types',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_doc_types'))
)
with op.batch_alter_table('doc_types', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_doc_types_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_doc_types_name'), ['name'], unique=True)
op.create_table('fabric',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_fabric'))
)
with op.batch_alter_table('fabric', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_fabric_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_fabric_name'), ['name'], unique=True)
op.create_table('groups_of_permissions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('group', sa.String(length=255), nullable=False),
@@ -30,6 +59,15 @@ def upgrade() -> None:
with op.batch_alter_table('groups_of_permissions', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_groups_of_permissions_id'), ['id'], unique=False)
op.create_table('markets',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_markets')),
sa.UniqueConstraint('name', name=op.f('uq_markets_name'))
)
with op.batch_alter_table('markets', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_markets_id'), ['id'], unique=False)
op.create_table('permissions',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('permission', sa.String(length=255), nullable=False),
@@ -38,17 +76,6 @@ def upgrade() -> None:
)
with op.batch_alter_table('permissions', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_permissions_id'), ['id'], unique=False)
op.execute(text("INSERT INTO permissions (permission) VALUES ('admin');"))
op.create_table('reports',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('filename', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.PrimaryKeyConstraint('id', name=op.f('pk_reports'))
)
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_reports_filename'), ['filename'], unique=False)
batch_op.create_index(batch_op.f('ix_reports_id'), ['id'], unique=False)
op.create_table('users',
sa.Column('id', sa.Uuid(), nullable=False),
@@ -66,6 +93,26 @@ def upgrade() -> None:
batch_op.create_index(batch_op.f('ix_users_last_name'), ['last_name'], unique=False)
batch_op.create_index(batch_op.f('ix_users_middle_name'), ['middle_name'], unique=False)
op.create_table('goods',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('article', sa.String(length=16), nullable=False),
sa.Column('price', sa.Numeric(precision=10, scale=2), nullable=False),
sa.Column('tnvd', sa.Integer(), nullable=False),
sa.Column('doc_type_id', sa.Integer(), nullable=False),
sa.Column('fabric_id', sa.Integer(), nullable=False),
sa.Column('status', sa.Boolean(), nullable=False),
sa.ForeignKeyConstraint(['doc_type_id'], ['doc_types.id'], name=op.f('fk_goods_doc_type_id_doc_types'), ondelete='CASCADE'),
sa.ForeignKeyConstraint(['fabric_id'], ['fabric.id'], name=op.f('fk_goods_fabric_id_fabric'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name=op.f('pk_goods'))
)
with op.batch_alter_table('goods', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_goods_article'), ['article'], unique=True)
batch_op.create_index(batch_op.f('ix_goods_doc_type_id'), ['doc_type_id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_fabric_id'), ['fabric_id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_price'), ['price'], unique=False)
batch_op.create_index(batch_op.f('ix_goods_tnvd'), ['tnvd'], unique=True)
op.create_table('group_permission',
sa.Column('group_id', sa.Integer(), nullable=False),
sa.Column('permission_id', sa.Integer(), nullable=False),
@@ -74,15 +121,15 @@ def upgrade() -> None:
sa.PrimaryKeyConstraint('group_id', 'permission_id', name=op.f('pk_group_permission'))
)
op.create_table('refresh_tokens',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('id', sa.Uuid(), nullable=False),
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('token_hash', sa.String(length=255), nullable=False),
sa.Column('device_info', sa.String(length=255), nullable=False),
sa.Column('ip_address', sa.String(length=45), nullable=False),
sa.Column('is_revoked', sa.Boolean(), nullable=False),
sa.Column('expires_at', sa.TIMESTAMP(), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
sa.Column('replaced_by', sa.Integer(), nullable=True),
sa.Column('expires_at', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('replaced_by', sa.Uuid(), nullable=True),
sa.ForeignKeyConstraint(['replaced_by'], ['refresh_tokens.id'], name=op.f('fk_refresh_tokens_replaced_by_refresh_tokens')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_refresh_tokens_user_id_users'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name=op.f('pk_refresh_tokens')),
@@ -92,18 +139,39 @@ def upgrade() -> None:
batch_op.create_index(batch_op.f('ix_refresh_tokens_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_refresh_tokens_user_id'), ['user_id'], unique=False)
op.create_table('reports',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('doc_id', sa.Uuid(), nullable=False),
sa.Column('filename', sa.String(length=255), nullable=False),
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('now()'), nullable=False),
sa.Column('uploaded_at', sa.TIMESTAMP(timezone=True), nullable=True),
sa.Column('doc_date', sa.TIMESTAMP(timezone=True), nullable=False),
sa.Column('status', sa.String(length=64), nullable=False),
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('market_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['market_id'], ['markets.id'], name=op.f('fk_reports_market_id_markets'), ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_reports_user_id_users'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id', name=op.f('pk_reports')),
sa.UniqueConstraint('doc_id', name=op.f('uq_reports_doc_id'))
)
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.create_index(batch_op.f('ix_reports_filename'), ['filename'], unique=False)
batch_op.create_index(batch_op.f('ix_reports_id'), ['id'], unique=False)
batch_op.create_index(batch_op.f('ix_reports_market_id'), ['market_id'], unique=False)
batch_op.create_index(batch_op.f('ix_reports_user_id'), ['user_id'], unique=False)
op.create_table('user_direct_permissions',
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('permission_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['permission_id'], ['permissions.id'], name=op.f('fk_user_direct_permissions_permission_id_permissions')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_user_direct_permissions_user_id_users')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_user_direct_permissions_user_id_users'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('user_id', 'permission_id', name=op.f('pk_user_direct_permissions'))
)
op.create_table('user_group',
sa.Column('user_id', sa.Uuid(), nullable=False),
sa.Column('permission_group_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['permission_group_id'], ['groups_of_permissions.id'], name=op.f('fk_user_group_permission_group_id_groups_of_permissions')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_user_group_user_id_users')),
sa.ForeignKeyConstraint(['user_id'], ['users.id'], name=op.f('fk_user_group_user_id_users'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('user_id', 'permission_group_id', name=op.f('pk_user_group'))
)
# ### end Alembic commands ###
@@ -114,12 +182,28 @@ def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_group')
op.drop_table('user_direct_permissions')
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_reports_user_id'))
batch_op.drop_index(batch_op.f('ix_reports_market_id'))
batch_op.drop_index(batch_op.f('ix_reports_id'))
batch_op.drop_index(batch_op.f('ix_reports_filename'))
op.drop_table('reports')
with op.batch_alter_table('refresh_tokens', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_refresh_tokens_user_id'))
batch_op.drop_index(batch_op.f('ix_refresh_tokens_id'))
op.drop_table('refresh_tokens')
op.drop_table('group_permission')
with op.batch_alter_table('goods', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_goods_tnvd'))
batch_op.drop_index(batch_op.f('ix_goods_price'))
batch_op.drop_index(batch_op.f('ix_goods_id'))
batch_op.drop_index(batch_op.f('ix_goods_fabric_id'))
batch_op.drop_index(batch_op.f('ix_goods_doc_type_id'))
batch_op.drop_index(batch_op.f('ix_goods_article'))
op.drop_table('goods')
with op.batch_alter_table('users', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_users_middle_name'))
batch_op.drop_index(batch_op.f('ix_users_last_name'))
@@ -127,17 +211,31 @@ def downgrade() -> None:
batch_op.drop_index(batch_op.f('ix_users_email'))
op.drop_table('users')
with op.batch_alter_table('reports', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_reports_id'))
batch_op.drop_index(batch_op.f('ix_reports_filename'))
op.drop_table('reports')
with op.batch_alter_table('permissions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_permissions_id'))
op.drop_table('permissions')
with op.batch_alter_table('markets', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_markets_id'))
op.drop_table('markets')
with op.batch_alter_table('groups_of_permissions', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_groups_of_permissions_id'))
op.drop_table('groups_of_permissions')
with op.batch_alter_table('fabric', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_fabric_name'))
batch_op.drop_index(batch_op.f('ix_fabric_id'))
op.drop_table('fabric')
with op.batch_alter_table('doc_types', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_doc_types_name'))
batch_op.drop_index(batch_op.f('ix_doc_types_id'))
op.drop_table('doc_types')
with op.batch_alter_table('accountant_settings', schema=None) as batch_op:
batch_op.drop_index(batch_op.f('ix_accountant_settings_name'))
batch_op.drop_index(batch_op.f('ix_accountant_settings_id'))
op.drop_table('accountant_settings')
# ### end Alembic commands ###
+6
View File
@@ -10,6 +10,12 @@ class Env(Base):
ACCESS_TOKEN_EXPIRE_MINUTES:int
REFRESH_TOKEN_EXPIRE_DAYS:int
DB_USER:str
DB_PASSWORD:str
DB_POSTGRESS:str
DB_HOST:str
DB_PORT:str
model_config=SettingsConfigDict(env_file="configs/.env", extra=None)
env_settings=Env() # type: ignore[call-arg]
+3 -1
View File
@@ -15,7 +15,9 @@ from sqlalchemy import (
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
engine = create_async_engine("sqlite+aiosqlite:///DB/database.db")
from src.models.configs_read.env import env_settings
engine = create_async_engine(f"postgresql+asyncpg://{env_settings.DB_USER}:{env_settings.DB_PASSWORD}@{env_settings.DB_HOST}:{env_settings.DB_PORT}/{env_settings.DB_POSTGRESS}")
'''remember as a boilerplate, or just cp/pst'''
class Model(DeclarativeBase):