fix: database migration
This commit is contained in:
parent
1bf6d6c6d7
commit
c1096ac4dd
@ -47,7 +47,7 @@ class Item(db.Model):
|
|||||||
|
|
||||||
Category = db.relationship("Category", secondary=item_category, lazy="dynamic", back_populates="Item")
|
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:
|
def __repr__(self) -> str:
|
||||||
return f"<Item {self.id} ({self.name})>"
|
return f"<Item {self.id} ({self.name})>"
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
"""full structure
|
"""full structure
|
||||||
|
|
||||||
Revision ID: 97738dc497a8
|
Revision ID: 9732721f062d
|
||||||
Revises: cec6bb222997
|
Revises:
|
||||||
Create Date: 2022-02-01 01:21:55.570500
|
Create Date: 2022-02-03 16:59:29.325840
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
@ -10,8 +10,8 @@ import sqlalchemy as sa
|
|||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = '97738dc497a8'
|
revision = '9732721f062d'
|
||||||
down_revision = 'cec6bb222997'
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
|
||||||
@ -28,6 +28,20 @@ def upgrade():
|
|||||||
sa.Column('name', sa.String(length=32), nullable=True),
|
sa.Column('name', sa.String(length=32), nullable=True),
|
||||||
sa.PrimaryKeyConstraint('id')
|
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',
|
op.create_table('amount__change',
|
||||||
sa.Column('item', sa.Integer(), nullable=False),
|
sa.Column('item', sa.Integer(), nullable=False),
|
||||||
sa.Column('date', sa.Date(), nullable=False),
|
sa.Column('date', sa.Date(), nullable=False),
|
||||||
@ -35,6 +49,15 @@ def upgrade():
|
|||||||
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
|
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
|
||||||
sa.PrimaryKeyConstraint('item', 'date')
|
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',
|
op.create_table('item_category',
|
||||||
sa.Column('item', sa.Integer(), nullable=False),
|
sa.Column('item', sa.Integer(), nullable=False),
|
||||||
sa.Column('category', sa.Integer(), nullable=False),
|
sa.Column('category', sa.Integer(), nullable=False),
|
||||||
@ -49,16 +72,17 @@ def upgrade():
|
|||||||
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
|
sa.ForeignKeyConstraint(['item'], ['item.id'], ),
|
||||||
sa.PrimaryKeyConstraint('item', 'date')
|
sa.PrimaryKeyConstraint('item', 'date')
|
||||||
)
|
)
|
||||||
op.create_foreign_key(None, 'item', 'brand', ['brand'], ['id'])
|
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.drop_constraint(None, 'item', type_='foreignkey')
|
|
||||||
op.drop_table('price__change')
|
op.drop_table('price__change')
|
||||||
op.drop_table('item_category')
|
op.drop_table('item_category')
|
||||||
|
op.drop_table('bought')
|
||||||
op.drop_table('amount__change')
|
op.drop_table('amount__change')
|
||||||
|
op.drop_table('item')
|
||||||
|
op.drop_table('user')
|
||||||
op.drop_table('category')
|
op.drop_table('category')
|
||||||
op.drop_table('brand')
|
op.drop_table('brand')
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
||||||
@ -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 ###
|
|
||||||
@ -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 ###
|
|
||||||
Loading…
x
Reference in New Issue
Block a user