0.1.4 models update

This commit is contained in:
2026-07-22 16:12:10 +03:00
parent 588bff725b
commit 8e66161ddd
12 changed files with 386 additions and 18 deletions
+69
View File
@@ -0,0 +1,69 @@
"""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 ###
+103
View File
@@ -0,0 +1,103 @@
"""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 ###
+40
View File
@@ -0,0 +1,40 @@
"""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 ###