so much stuff lol

This commit is contained in:
2025-04-09 23:53:05 -04:00
parent 1c00ea8569
commit df6490cab0
40 changed files with 1909 additions and 277 deletions

1
alembic/README Normal file
View File

@ -0,0 +1 @@
Generic single-database configuration.

84
alembic/env.py Normal file
View File

@ -0,0 +1,84 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
# Import your models here
from app.db.database import Base
from app.models.inventory import Inventory
from app.models.card import Card
from app.models.box import Box, OpenBox
from app.models.game import Game
from app.models.file import File
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(
connection=connection, target_metadata=target_metadata
)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

26
alembic/script.py.mako Normal file
View File

@ -0,0 +1,26 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision: str = ${repr(up_revision)}
down_revision: Union[str, None] = ${repr(down_revision)}
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@ -0,0 +1,49 @@
"""create tcgplayer categories table
Revision ID: 2025_04_09_create_tcgplayer_categories_table
Revises: remove_product_id_unique_constraint
Create Date: 2025-04-09 23:20:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '2025_04_09_create_tcgplayer_categories_table'
down_revision: str = 'remove_product_id_unique_constraint'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table('tcgplayer_categories',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('category_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('display_name', sa.String(), nullable=True),
sa.Column('seo_category_name', sa.String(), nullable=True),
sa.Column('category_description', sa.String(), nullable=True),
sa.Column('category_page_title', sa.String(), nullable=True),
sa.Column('sealed_label', sa.String(), nullable=True),
sa.Column('non_sealed_label', sa.String(), nullable=True),
sa.Column('condition_guide_url', sa.String(), nullable=True),
sa.Column('is_scannable', sa.Boolean(), nullable=True, default=False),
sa.Column('popularity', sa.Integer(), nullable=True, default=0),
sa.Column('is_direct', sa.Boolean(), nullable=True, default=False),
sa.Column('modified_on', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('category_id')
)
op.create_index('ix_tcgplayer_categories_id', 'tcgplayer_categories', ['id'], unique=False)
op.create_index('ix_tcgplayer_categories_category_id', 'tcgplayer_categories', ['category_id'], unique=True)
def downgrade() -> None:
op.drop_index('ix_tcgplayer_categories_category_id', table_name='tcgplayer_categories')
op.drop_index('ix_tcgplayer_categories_id', table_name='tcgplayer_categories')
op.drop_table('tcgplayer_categories')

View File

@ -0,0 +1,171 @@
"""create inventory table
Revision ID: 4dbeb89dd33a
Revises:
Create Date: 2025-04-09 21:56:49.068087
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = '4dbeb89dd33a'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('boxes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=True),
sa.Column('type', sa.String(), nullable=True),
sa.Column('set_code', sa.String(), nullable=True),
sa.Column('sku', sa.Integer(), nullable=True),
sa.Column('name', sa.String(), nullable=True),
sa.Column('expected_number_of_cards', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_boxes_id'), 'boxes', ['id'], unique=False)
op.create_table('cards',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('rarity', sa.String(), nullable=True),
sa.Column('set_name', sa.String(), nullable=True),
sa.Column('price', sa.Float(), nullable=True),
sa.Column('quantity', sa.Integer(), nullable=True),
sa.Column('tcgplayer_sku', sa.String(), nullable=True),
sa.Column('product_line', sa.String(), nullable=True),
sa.Column('product_name', sa.String(), nullable=True),
sa.Column('title', sa.String(), nullable=True),
sa.Column('number', sa.String(), nullable=True),
sa.Column('condition', sa.String(), nullable=True),
sa.Column('tcg_market_price', sa.Float(), nullable=True),
sa.Column('tcg_direct_low', sa.Float(), nullable=True),
sa.Column('tcg_low_price_with_shipping', sa.Float(), nullable=True),
sa.Column('tcg_low_price', sa.Float(), nullable=True),
sa.Column('total_quantity', sa.Integer(), nullable=True),
sa.Column('add_to_quantity', sa.Integer(), nullable=True),
sa.Column('tcg_marketplace_price', sa.Float(), nullable=True),
sa.Column('photo_url', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_cards_id'), 'cards', ['id'], unique=False)
op.create_index(op.f('ix_cards_name'), 'cards', ['name'], unique=False)
op.create_index(op.f('ix_cards_set_name'), 'cards', ['set_name'], unique=False)
op.create_index(op.f('ix_cards_tcgplayer_sku'), 'cards', ['tcgplayer_sku'], unique=True)
op.create_table('files',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('type', sa.String(), nullable=True),
sa.Column('path', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_files_id'), 'files', ['id'], unique=False)
op.create_table('games',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_games_id'), 'games', ['id'], unique=False)
op.create_table('inventory',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('tcgplayer_id', sa.String(), nullable=True),
sa.Column('product_line', sa.String(), nullable=True),
sa.Column('set_name', sa.String(), nullable=True),
sa.Column('product_name', sa.String(), nullable=True),
sa.Column('title', sa.String(), nullable=True),
sa.Column('number', sa.String(), nullable=True),
sa.Column('rarity', sa.String(), nullable=True),
sa.Column('condition', sa.String(), nullable=True),
sa.Column('tcg_market_price', sa.Float(), nullable=True),
sa.Column('tcg_direct_low', sa.Float(), nullable=True),
sa.Column('tcg_low_price_with_shipping', sa.Float(), nullable=True),
sa.Column('tcg_low_price', sa.Float(), nullable=True),
sa.Column('total_quantity', sa.Integer(), nullable=True),
sa.Column('add_to_quantity', sa.Integer(), nullable=True),
sa.Column('tcg_marketplace_price', sa.Float(), nullable=True),
sa.Column('photo_url', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_inventory_id'), 'inventory', ['id'], unique=False)
op.create_index(op.f('ix_inventory_tcgplayer_id'), 'inventory', ['tcgplayer_id'], unique=True)
op.create_table('open_boxes',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('box_id', sa.Integer(), nullable=True),
sa.Column('number_of_cards', sa.Integer(), nullable=True),
sa.Column('date_opened', sa.DateTime(timezone=True), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['box_id'], ['boxes.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_open_boxes_id'), 'open_boxes', ['id'], unique=False)
op.create_table('tcgplayer_products',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('clean_name', sa.String(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('url', sa.String(), nullable=True),
sa.Column('modified_on', sa.DateTime(), nullable=True),
sa.Column('image_count', sa.Integer(), nullable=True),
sa.Column('ext_rarity', sa.String(), nullable=True),
sa.Column('ext_number', sa.String(), nullable=True),
sa.Column('low_price', sa.Float(), nullable=True),
sa.Column('mid_price', sa.Float(), nullable=True),
sa.Column('high_price', sa.Float(), nullable=True),
sa.Column('market_price', sa.Float(), nullable=True),
sa.Column('direct_low_price', sa.Float(), nullable=True),
sa.Column('sub_type_name', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('product_id')
)
op.create_index(op.f('ix_tcgplayer_products_id'), 'tcgplayer_products', ['id'], unique=False)
op.create_index(op.f('ix_tcgplayer_products_product_id'), 'tcgplayer_products', ['product_id'], unique=True)
# ### end Alembic commands ###
def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f('ix_tcgplayer_products_product_id'), table_name='tcgplayer_products')
op.drop_index(op.f('ix_tcgplayer_products_id'), table_name='tcgplayer_products')
op.drop_index(op.f('ix_open_boxes_id'), table_name='open_boxes')
op.drop_table('open_boxes')
op.drop_index(op.f('ix_inventory_tcgplayer_id'), table_name='inventory')
op.drop_index(op.f('ix_inventory_id'), table_name='inventory')
op.drop_table('inventory')
op.drop_index(op.f('ix_games_id'), table_name='games')
op.drop_table('games')
op.drop_index(op.f('ix_files_id'), table_name='files')
op.drop_table('files')
op.drop_index(op.f('ix_cards_tcgplayer_sku'), table_name='cards')
op.drop_index(op.f('ix_cards_set_name'), table_name='cards')
op.drop_index(op.f('ix_cards_name'), table_name='cards')
op.drop_index(op.f('ix_cards_id'), table_name='cards')
op.drop_table('cards')
op.drop_index(op.f('ix_boxes_id'), table_name='boxes')
op.drop_table('boxes')
# ### end Alembic commands ###

View File

@ -0,0 +1,49 @@
"""create tcgplayer categories table
Revision ID: create_tcgplayer_categories_table
Revises: remove_product_id_unique_constraint
Create Date: 2025-04-09 23:20:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'create_tcgplayer_categories_table'
down_revision: str = 'remove_product_id_unique_constraint'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.create_table('tcgplayer_categories',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('category_id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('display_name', sa.String(), nullable=True),
sa.Column('seo_category_name', sa.String(), nullable=True),
sa.Column('category_description', sa.String(), nullable=True),
sa.Column('category_page_title', sa.String(), nullable=True),
sa.Column('sealed_label', sa.String(), nullable=True),
sa.Column('non_sealed_label', sa.String(), nullable=True),
sa.Column('condition_guide_url', sa.String(), nullable=True),
sa.Column('is_scannable', sa.Boolean(), nullable=True, default=False),
sa.Column('popularity', sa.Integer(), nullable=True, default=0),
sa.Column('is_direct', sa.Boolean(), nullable=True, default=False),
sa.Column('modified_on', sa.DateTime(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('category_id')
)
op.create_index('ix_tcgplayer_categories_id', 'tcgplayer_categories', ['id'], unique=False)
op.create_index('ix_tcgplayer_categories_category_id', 'tcgplayer_categories', ['category_id'], unique=True)
def downgrade() -> None:
op.drop_index('ix_tcgplayer_categories_category_id', table_name='tcgplayer_categories')
op.drop_index('ix_tcgplayer_categories_id', table_name='tcgplayer_categories')
op.drop_table('tcgplayer_categories')

View File

@ -0,0 +1,101 @@
"""remove product_id unique constraint
Revision ID: remove_product_id_unique_constraint
Revises: 4dbeb89dd33a
Create Date: 2025-04-09 23:10:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'remove_product_id_unique_constraint'
down_revision: str = '4dbeb89dd33a'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# Create a new table without the unique constraint
op.create_table('tcgplayer_products_new',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(), nullable=False),
sa.Column('clean_name', sa.String(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('url', sa.String(), nullable=True),
sa.Column('modified_on', sa.DateTime(), nullable=True),
sa.Column('image_count', sa.Integer(), nullable=True),
sa.Column('ext_rarity', sa.String(), nullable=True),
sa.Column('ext_number', sa.String(), nullable=True),
sa.Column('low_price', sa.Float(), nullable=True),
sa.Column('mid_price', sa.Float(), nullable=True),
sa.Column('high_price', sa.Float(), nullable=True),
sa.Column('market_price', sa.Float(), nullable=True),
sa.Column('direct_low_price', sa.Float(), nullable=True),
sa.Column('sub_type_name', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.ForeignKeyConstraint(['group_id'], ['tcgplayer_groups.group_id'])
)
# Copy data from old table to new table
op.execute('INSERT INTO tcgplayer_products_new SELECT * FROM tcgplayer_products')
# Drop old table
op.drop_table('tcgplayer_products')
# Rename new table to old table name
op.rename_table('tcgplayer_products_new', 'tcgplayer_products')
# Create indexes
op.create_index('ix_tcgplayer_products_id', 'tcgplayer_products', ['id'], unique=False)
op.create_index('ix_tcgplayer_products_product_id', 'tcgplayer_products', ['product_id'], unique=False)
def downgrade() -> None:
# Create a new table with the unique constraint
op.create_table('tcgplayer_products_new',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('product_id', sa.Integer(), nullable=True),
sa.Column('name', sa.String(), nullable=False),
sa.Column('clean_name', sa.String(), nullable=True),
sa.Column('image_url', sa.String(), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('url', sa.String(), nullable=True),
sa.Column('modified_on', sa.DateTime(), nullable=True),
sa.Column('image_count', sa.Integer(), nullable=True),
sa.Column('ext_rarity', sa.String(), nullable=True),
sa.Column('ext_number', sa.String(), nullable=True),
sa.Column('low_price', sa.Float(), nullable=True),
sa.Column('mid_price', sa.Float(), nullable=True),
sa.Column('high_price', sa.Float(), nullable=True),
sa.Column('market_price', sa.Float(), nullable=True),
sa.Column('direct_low_price', sa.Float(), nullable=True),
sa.Column('sub_type_name', sa.String(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('CURRENT_TIMESTAMP'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('product_id'),
sa.ForeignKeyConstraint(['group_id'], ['tcgplayer_groups.group_id'])
)
# Copy data from old table to new table
op.execute('INSERT INTO tcgplayer_products_new SELECT * FROM tcgplayer_products')
# Drop old table
op.drop_table('tcgplayer_products')
# Rename new table to old table name
op.rename_table('tcgplayer_products_new', 'tcgplayer_products')
# Create indexes
op.create_index('ix_tcgplayer_products_id', 'tcgplayer_products', ['id'], unique=False)
op.create_index('ix_tcgplayer_products_product_id', 'tcgplayer_products', ['product_id'], unique=True)