more inventory management work
This commit is contained in:
@ -28,6 +28,13 @@ target_metadata = Base.metadata
|
||||
# ... etc.
|
||||
|
||||
|
||||
def include_object(object, name, type_, reflected, compare_to):
|
||||
# Skip materialized views during migrations
|
||||
if type_ == "table" and name == "most_recent_tcgplayer_price":
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def run_migrations_offline() -> None:
|
||||
"""Run migrations in 'offline' mode.
|
||||
|
||||
@ -46,6 +53,7 @@ def run_migrations_offline() -> None:
|
||||
target_metadata=target_metadata,
|
||||
literal_binds=True,
|
||||
dialect_opts={"paramstyle": "named"},
|
||||
include_object=include_object,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
@ -67,7 +75,9 @@ def run_migrations_online() -> None:
|
||||
|
||||
with connectable.connect() as connection:
|
||||
context.configure(
|
||||
connection=connection, target_metadata=target_metadata
|
||||
connection=connection,
|
||||
target_metadata=target_metadata,
|
||||
include_object=include_object,
|
||||
)
|
||||
|
||||
with context.begin_transaction():
|
||||
@ -77,4 +87,4 @@ def run_migrations_online() -> None:
|
||||
if context.is_offline_mode():
|
||||
run_migrations_offline()
|
||||
else:
|
||||
run_migrations_online()
|
||||
run_migrations_online()
|
34
alembic/versions/06605c625998_product.py
Normal file
34
alembic/versions/06605c625998_product.py
Normal file
@ -0,0 +1,34 @@
|
||||
"""product
|
||||
|
||||
Revision ID: 06605c625998
|
||||
Revises: 28cfdbde1796
|
||||
Create Date: 2025-04-22 10:10:18.082314
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '06605c625998'
|
||||
down_revision: Union[str, None] = '28cfdbde1796'
|
||||
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.drop_constraint('physical_items_product_id_fkey', 'physical_items', type_='foreignkey')
|
||||
op.create_foreign_key(None, 'physical_items', 'tcgplayer_products', ['product_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'physical_items', type_='foreignkey')
|
||||
op.create_foreign_key('physical_items_product_id_fkey', 'physical_items', 'products', ['product_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
@ -0,0 +1,97 @@
|
||||
"""inventory management improvements
|
||||
|
||||
Revision ID: 32d21f7d33e9
|
||||
Revises: d2c33dee079c
|
||||
Create Date: 2025-04-22 16:43:57.844419
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '32d21f7d33e9'
|
||||
down_revision: Union[str, None] = 'd2c33dee079c'
|
||||
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('marketplaces',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('name', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_marketplaces_id'), 'marketplaces', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_marketplaces_name'), 'marketplaces', ['name'], unique=True)
|
||||
op.create_table('sealed_expected_values',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('product_id', sa.Integer(), nullable=True),
|
||||
sa.Column('expected_value', sa.Float(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['product_id'], ['tcgplayer_products.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_sealed_expected_values_id'), 'sealed_expected_values', ['id'], unique=False)
|
||||
op.create_table('marketplace_listings',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('inventory_item_id', sa.Integer(), nullable=False),
|
||||
sa.Column('marketplace_id', sa.Integer(), nullable=False),
|
||||
sa.Column('product_id', sa.Integer(), nullable=False),
|
||||
sa.Column('listing_date', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('delisting_date', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('listed_price', sa.Float(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['inventory_item_id'], ['inventory_items.id'], ),
|
||||
sa.ForeignKeyConstraint(['marketplace_id'], ['marketplaces.id'], ),
|
||||
sa.ForeignKeyConstraint(['product_id'], ['tcgplayer_products.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_marketplace_listings_id'), 'marketplace_listings', ['id'], unique=False)
|
||||
op.drop_index('ix_product_expected_values_id', table_name='product_expected_values')
|
||||
op.drop_table('product_expected_values')
|
||||
op.add_column('sealed_boxes', sa.Column('expected_value', sa.Float(), nullable=True))
|
||||
op.add_column('sealed_cases', sa.Column('expected_value', sa.Float(), nullable=True))
|
||||
op.add_column('sealed_cases', sa.Column('num_boxes', sa.Integer(), nullable=True))
|
||||
op.add_column('transactions', sa.Column('marketplace_id', sa.Integer(), nullable=True))
|
||||
op.create_foreign_key(None, 'transactions', 'marketplaces', ['marketplace_id'], ['id'])
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint(None, 'transactions', type_='foreignkey')
|
||||
op.drop_column('transactions', 'marketplace_id')
|
||||
op.drop_column('sealed_cases', 'num_boxes')
|
||||
op.drop_column('sealed_cases', 'expected_value')
|
||||
op.drop_column('sealed_boxes', 'expected_value')
|
||||
op.create_table('product_expected_values',
|
||||
sa.Column('id', sa.INTEGER(), autoincrement=True, nullable=False),
|
||||
sa.Column('product_id', sa.INTEGER(), autoincrement=False, nullable=True),
|
||||
sa.Column('expected_value', sa.DOUBLE_PRECISION(precision=53), autoincrement=False, nullable=True),
|
||||
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
|
||||
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
|
||||
sa.Column('deleted_at', postgresql.TIMESTAMP(timezone=True), autoincrement=False, nullable=True),
|
||||
sa.ForeignKeyConstraint(['product_id'], ['tcgplayer_products.id'], name='product_expected_values_product_id_fkey'),
|
||||
sa.PrimaryKeyConstraint('id', name='product_expected_values_pkey')
|
||||
)
|
||||
op.create_index('ix_product_expected_values_id', 'product_expected_values', ['id'], unique=False)
|
||||
op.drop_index(op.f('ix_marketplace_listings_id'), table_name='marketplace_listings')
|
||||
op.drop_table('marketplace_listings')
|
||||
op.drop_index(op.f('ix_sealed_expected_values_id'), table_name='sealed_expected_values')
|
||||
op.drop_table('sealed_expected_values')
|
||||
op.drop_index(op.f('ix_marketplaces_name'), table_name='marketplaces')
|
||||
op.drop_index(op.f('ix_marketplaces_id'), table_name='marketplaces')
|
||||
op.drop_table('marketplaces')
|
||||
# ### end Alembic commands ###
|
55
alembic/versions/d2c33dee079c_small_change_and_mat_view.py
Normal file
55
alembic/versions/d2c33dee079c_small_change_and_mat_view.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""small change and mat view
|
||||
|
||||
Revision ID: d2c33dee079c
|
||||
Revises: 06605c625998
|
||||
Create Date: 2025-04-22 10:27:25.322827
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'd2c33dee079c'
|
||||
down_revision: Union[str, None] = '06605c625998'
|
||||
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('product_expected_values',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('product_id', sa.Integer(), nullable=True),
|
||||
sa.Column('expected_value', sa.Float(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
|
||||
sa.ForeignKeyConstraint(['product_id'], ['tcgplayer_products.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_product_expected_values_id'), 'product_expected_values', ['id'], unique=False)
|
||||
op.execute("""
|
||||
CREATE MATERIALIZED VIEW IF NOT EXISTS most_recent_tcgplayer_price AS
|
||||
SELECT DISTINCT ON (product_id) *
|
||||
FROM public.tcgplayer_price_history
|
||||
ORDER BY product_id, date DESC;
|
||||
""")
|
||||
op.execute("""
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS idx_most_recent_tcgplayer_price_product_id
|
||||
ON most_recent_tcgplayer_price (product_id);
|
||||
""")
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_product_expected_values_id'), table_name='product_expected_values')
|
||||
op.drop_table('product_expected_values')
|
||||
op.execute("DROP INDEX IF EXISTS idx_most_recent_tcgplayer_price_product_id;")
|
||||
op.execute("DROP MATERIALIZED VIEW IF EXISTS most_recent_tcgplayer_price;")
|
||||
# ### end Alembic commands ###
|
Reference in New Issue
Block a user