fix: database migration

This commit is contained in:
Lunaresk 2022-02-03 17:03:37 +01:00
parent 1bf6d6c6d7
commit c1096ac4dd
4 changed files with 32 additions and 84 deletions

View File

@ -47,7 +47,7 @@ class Item(db.Model):
Category = db.relationship("Category", secondary=item_category, lazy="dynamic", back_populates="Item")
product = db.relationship("Bought", backref='Item', lazy='dynamic')
Item = db.relationship("Bought", backref='Item', lazy='dynamic')
def __repr__(self) -> str:
return f"<Item {self.id} ({self.name})>"

View File

@ -1,8 +1,8 @@
"""full structure
Revision ID: 97738dc497a8
Revises: cec6bb222997
Create Date: 2022-02-01 01:21:55.570500
Revision ID: 9732721f062d
Revises:
Create Date: 2022-02-03 16:59:29.325840
"""
from alembic import op
@ -10,8 +10,8 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '97738dc497a8'
down_revision = 'cec6bb222997'
revision = '9732721f062d'
down_revision = None
branch_labels = None
depends_on = None
@ -28,6 +28,20 @@ def upgrade():
sa.Column('name', sa.String(length=32), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.String(length=10), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('password_hash', sa.String(length=128), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('item',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('brand', sa.Integer(), nullable=True),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.ForeignKeyConstraint(['brand'], ['brand.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('amount__change',
sa.Column('item', sa.Integer(), nullable=False),
sa.Column('date', sa.Date(), nullable=False),
@ -35,6 +49,15 @@ def upgrade():
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
sa.PrimaryKeyConstraint('item', 'date')
)
op.create_table('bought',
sa.Column('user', sa.String(length=10), nullable=False),
sa.Column('item', sa.Integer(), nullable=False),
sa.Column('date', sa.Date(), nullable=True),
sa.Column('amount', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
sa.ForeignKeyConstraint(['user'], ['user.id'], ),
sa.PrimaryKeyConstraint('user', 'item')
)
op.create_table('item_category',
sa.Column('item', sa.Integer(), nullable=False),
sa.Column('category', sa.Integer(), nullable=False),
@ -49,16 +72,17 @@ def upgrade():
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
sa.PrimaryKeyConstraint('item', 'date')
)
op.create_foreign_key(None, 'item', 'brand', ['brand'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'item', type_='foreignkey')
op.drop_table('price__change')
op.drop_table('item_category')
op.drop_table('bought')
op.drop_table('amount__change')
op.drop_table('item')
op.drop_table('user')
op.drop_table('category')
op.drop_table('brand')
# ### end Alembic commands ###

View File

@ -1,32 +0,0 @@
"""users table
Revision ID: c9dcd301d327
Revises:
Create Date: 2022-01-20 22:58:43.707307
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c9dcd301d327'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('user',
sa.Column('id', sa.String(length=10), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user')
# ### end Alembic commands ###

View File

@ -1,44 +0,0 @@
"""bought and item
Revision ID: cec6bb222997
Revises: c9dcd301d327
Create Date: 2022-01-21 09:38:53.679649
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'cec6bb222997'
down_revision = 'c9dcd301d327'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('item',
sa.Column('id', sa.BigInteger(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('brand', sa.String(length=32), nullable=True),
sa.Column('description', sa.Text(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('bought',
sa.Column('user', sa.String(length=10), nullable=False),
sa.Column('item', sa.BigInteger(), nullable=False),
sa.Column('date', sa.Date(), nullable=True),
sa.Column('amount', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
sa.ForeignKeyConstraint(['user'], ['user.id'], ),
sa.PrimaryKeyConstraint('user', 'item')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('bought')
op.drop_table('item')
# ### end Alembic commands ###