major refactoring adding vendor and customer features
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
# alembic/env.py
|
||||
import os
|
||||
import sys
|
||||
from logging.config import fileConfig
|
||||
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
|
||||
from alembic import context
|
||||
|
||||
# Add your project directory to the Python path
|
||||
@@ -16,57 +16,77 @@ from models.database.base import Base
|
||||
# Only import SQLAlchemy models, not Pydantic API models
|
||||
print("[ALEMBIC] Importing database models...")
|
||||
|
||||
# Core models
|
||||
try:
|
||||
from models.database.user import User
|
||||
print(" ✓ User model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ User model failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.vendor import Vendor, VendorUser, Role
|
||||
print(" ✓ Vendor models imported (Vendor, VendorUser, Role)")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Vendor models failed: {e}")
|
||||
|
||||
# Product models
|
||||
try:
|
||||
from models.database.marketplace_product import MarketplaceProduct
|
||||
print(" ✓ MarketplaceProduct model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ MarketplaceProduct model failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.stock import Stock
|
||||
print(" ✓ Stock model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Stock model failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.vendor import Vendor
|
||||
print(" ✓ Vendor model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Vendor model failed: {e}")
|
||||
|
||||
try:
|
||||
from models.database.product import Product
|
||||
print(" ✓ Product model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Product model failed: {e}")
|
||||
|
||||
# Inventory
|
||||
try:
|
||||
from models.database.inventory import Inventory
|
||||
print(" ✓ Inventory model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Inventory model failed: {e}")
|
||||
|
||||
# Marketplace imports
|
||||
try:
|
||||
from models.database.marketplace_import_job import MarketplaceImportJob
|
||||
print(" ✓ Marketplace model imported")
|
||||
print(" ✓ MarketplaceImportJob model imported")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Marketplace model failed: {e}")
|
||||
print(f" ✗ MarketplaceImportJob model failed: {e}")
|
||||
|
||||
# Check if there are any additional models in the database directory
|
||||
# Customer models (MISSING IN YOUR FILE)
|
||||
try:
|
||||
from models.database import auth as auth_models
|
||||
print(" ✓ Auth models imported")
|
||||
except ImportError:
|
||||
print(" - Auth models not found (optional)")
|
||||
from models.database.customer import Customer, CustomerAddress
|
||||
print(" ✓ Customer models imported (Customer, CustomerAddress)")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Customer models failed: {e}")
|
||||
|
||||
# Order models (MISSING IN YOUR FILE)
|
||||
try:
|
||||
from models.database import admin as admin_models
|
||||
print(" ✓ Admin models imported")
|
||||
except ImportError:
|
||||
print(" - Admin models not found (optional)")
|
||||
from models.database.order import Order, OrderItem
|
||||
print(" ✓ Order models imported (Order, OrderItem)")
|
||||
except ImportError as e:
|
||||
print(f" ✗ Order models failed: {e}")
|
||||
|
||||
print(f"[ALEMBIC] Model import completed. Tables found: {list(Base.metadata.tables.keys())}")
|
||||
print(f"[ALEMBIC] Total tables to create: {len(Base.metadata.tables)}")
|
||||
# Payment models (if you have them)
|
||||
try:
|
||||
from models.database.payment import Payment
|
||||
print(" ✓ Payment model imported")
|
||||
except ImportError as e:
|
||||
print(f" - Payment model not found (optional)")
|
||||
|
||||
# Shipping models (if you have them)
|
||||
try:
|
||||
from models.database.shipping import ShippingAddress
|
||||
print(" ✓ Shipping model imported")
|
||||
except ImportError as e:
|
||||
print(f" - Shipping model not found (optional)")
|
||||
|
||||
print(f"\n[ALEMBIC] Model import completed.")
|
||||
print(f"[ALEMBIC] Tables found: {list(Base.metadata.tables.keys())}")
|
||||
print(f"[ALEMBIC] Total tables to create: {len(Base.metadata.tables)}\n")
|
||||
|
||||
# Alembic Config object
|
||||
config = context.config
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
"""initial_complete_schema
|
||||
|
||||
Revision ID: dbe48f596a44
|
||||
Revises:
|
||||
Create Date: 2025-09-21 15:45:40.290712
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'dbe48f596a44'
|
||||
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('products',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('marketplace_product_id', sa.String(), nullable=False),
|
||||
sa.Column('title', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.String(), nullable=True),
|
||||
sa.Column('link', sa.String(), nullable=True),
|
||||
sa.Column('image_link', sa.String(), nullable=True),
|
||||
sa.Column('availability', sa.String(), nullable=True),
|
||||
sa.Column('price', sa.String(), nullable=True),
|
||||
sa.Column('brand', sa.String(), nullable=True),
|
||||
sa.Column('gtin', sa.String(), nullable=True),
|
||||
sa.Column('mpn', sa.String(), nullable=True),
|
||||
sa.Column('condition', sa.String(), nullable=True),
|
||||
sa.Column('adult', sa.String(), nullable=True),
|
||||
sa.Column('multipack', sa.Integer(), nullable=True),
|
||||
sa.Column('is_bundle', sa.String(), nullable=True),
|
||||
sa.Column('age_group', sa.String(), nullable=True),
|
||||
sa.Column('color', sa.String(), nullable=True),
|
||||
sa.Column('gender', sa.String(), nullable=True),
|
||||
sa.Column('material', sa.String(), nullable=True),
|
||||
sa.Column('pattern', sa.String(), nullable=True),
|
||||
sa.Column('size', sa.String(), nullable=True),
|
||||
sa.Column('size_type', sa.String(), nullable=True),
|
||||
sa.Column('size_system', sa.String(), nullable=True),
|
||||
sa.Column('item_group_id', sa.String(), nullable=True),
|
||||
sa.Column('google_product_category', sa.String(), nullable=True),
|
||||
sa.Column('product_type', sa.String(), nullable=True),
|
||||
sa.Column('custom_label_0', sa.String(), nullable=True),
|
||||
sa.Column('custom_label_1', sa.String(), nullable=True),
|
||||
sa.Column('custom_label_2', sa.String(), nullable=True),
|
||||
sa.Column('custom_label_3', sa.String(), nullable=True),
|
||||
sa.Column('custom_label_4', sa.String(), nullable=True),
|
||||
sa.Column('additional_image_link', sa.String(), nullable=True),
|
||||
sa.Column('sale_price', sa.String(), nullable=True),
|
||||
sa.Column('unit_pricing_measure', sa.String(), nullable=True),
|
||||
sa.Column('unit_pricing_base_measure', sa.String(), nullable=True),
|
||||
sa.Column('identifier_exists', sa.String(), nullable=True),
|
||||
sa.Column('shipping', sa.String(), nullable=True),
|
||||
sa.Column('currency', sa.String(), nullable=True),
|
||||
sa.Column('marketplace', sa.String(), nullable=True),
|
||||
sa.Column('vendor_name', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('idx_marketplace_brand', 'products', ['marketplace', 'brand'], unique=False)
|
||||
op.create_index('idx_marketplace_shop', 'products', ['marketplace', 'vendor_name'], unique=False)
|
||||
op.create_index(op.f('ix_products_availability'), 'products', ['availability'], unique=False)
|
||||
op.create_index(op.f('ix_products_brand'), 'products', ['brand'], unique=False)
|
||||
op.create_index(op.f('ix_products_google_product_category'), 'products', ['google_product_category'], unique=False)
|
||||
op.create_index(op.f('ix_products_gtin'), 'products', ['gtin'], unique=False)
|
||||
op.create_index(op.f('ix_products_id'), 'products', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_products_marketplace'), 'products', ['marketplace'], unique=False)
|
||||
op.create_index(op.f('ix_products_product_id'), 'products', ['marketplace_product_id'], unique=True)
|
||||
op.create_index(op.f('ix_products_vendor_name'), 'products', ['vendor_name'], unique=False)
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('email', sa.String(), nullable=False),
|
||||
sa.Column('username', sa.String(), nullable=False),
|
||||
sa.Column('hashed_password', sa.String(), nullable=False),
|
||||
sa.Column('role', sa.String(), nullable=False),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=False),
|
||||
sa.Column('last_login', sa.DateTime(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
||||
op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
||||
op.create_table('vendors',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('vendor_code', sa.String(), nullable=False),
|
||||
sa.Column('vendor_name', sa.String(), nullable=False),
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('owner_id', sa.Integer(), nullable=False),
|
||||
sa.Column('contact_email', sa.String(), nullable=True),
|
||||
sa.Column('contact_phone', sa.String(), nullable=True),
|
||||
sa.Column('website', sa.String(), nullable=True),
|
||||
sa.Column('business_address', sa.Text(), nullable=True),
|
||||
sa.Column('tax_number', sa.String(), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_verified', sa.Boolean(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index(op.f('ix_vendors_id'), 'vendors', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_vendors_vendor_code'), 'vendors', ['vendor_code'], unique=True)
|
||||
op.create_table('marketplace_import_jobs',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('status', sa.String(), nullable=False),
|
||||
sa.Column('source_url', sa.String(), nullable=False),
|
||||
sa.Column('marketplace', sa.String(), nullable=False),
|
||||
sa.Column('vendor_name', sa.String(), nullable=False),
|
||||
sa.Column('vendor_id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('imported_count', sa.Integer(), nullable=True),
|
||||
sa.Column('updated_count', sa.Integer(), nullable=True),
|
||||
sa.Column('error_count', sa.Integer(), nullable=True),
|
||||
sa.Column('total_processed', sa.Integer(), nullable=True),
|
||||
sa.Column('error_message', sa.String(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('started_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('completed_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['vendor_id'], ['vendors.id'], ),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_index('idx_marketplace_import_vendor_id', 'marketplace_import_jobs', ['vendor_id'], unique=False)
|
||||
op.create_index('idx_marketplace_import_vendor_status', 'marketplace_import_jobs', ['status'], unique=False)
|
||||
op.create_index('idx_marketplace_import_user_marketplace', 'marketplace_import_jobs', ['user_id', 'marketplace'], unique=False)
|
||||
op.create_index(op.f('ix_marketplace_import_jobs_id'), 'marketplace_import_jobs', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_marketplace_import_jobs_marketplace'), 'marketplace_import_jobs', ['marketplace'], unique=False)
|
||||
op.create_index(op.f('ix_marketplace_import_jobs_vendor_name'), 'marketplace_import_jobs', ['vendor_name'], unique=False)
|
||||
op.create_table('vendor_products',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('vendor_id', sa.Integer(), nullable=False),
|
||||
sa.Column('marketplace_product_id', sa.Integer(), nullable=False),
|
||||
sa.Column('vendor_product_id', sa.String(), nullable=True),
|
||||
sa.Column('price', sa.Float(), nullable=True),
|
||||
sa.Column('vendor_sale_price', sa.Float(), nullable=True),
|
||||
sa.Column('vendor_currency', sa.String(), nullable=True),
|
||||
sa.Column('vendor_availability', sa.String(), nullable=True),
|
||||
sa.Column('vendor_condition', sa.String(), nullable=True),
|
||||
sa.Column('is_featured', sa.Boolean(), nullable=True),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=True),
|
||||
sa.Column('display_order', sa.Integer(), nullable=True),
|
||||
sa.Column('min_quantity', sa.Integer(), nullable=True),
|
||||
sa.Column('max_quantity', sa.Integer(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=True),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
||||
sa.ForeignKeyConstraint(['marketplace_product_id'], ['products.id'], ),
|
||||
sa.ForeignKeyConstraint(['vendor_id'], ['vendors.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('vendor_id', 'marketplace_product_id', name='uq_vendor_product')
|
||||
)
|
||||
op.create_index('idx_vendor_product_active', 'vendor_products', ['vendor_id', 'is_active'], unique=False)
|
||||
op.create_index('idx_vendor_product_featured', 'vendor_products', ['vendor_id', 'is_featured'], unique=False)
|
||||
op.create_index(op.f('ix_vendor_products_id'), 'vendor_products', ['id'], unique=False)
|
||||
op.create_table('stock',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('gtin', sa.String(), nullable=False),
|
||||
sa.Column('location', sa.String(), nullable=False),
|
||||
sa.Column('quantity', sa.Integer(), nullable=False),
|
||||
sa.Column('reserved_quantity', sa.Integer(), nullable=True),
|
||||
sa.Column('vendor_id', sa.Integer(), nullable=True),
|
||||
sa.Column('created_at', sa.DateTime(), nullable=False),
|
||||
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
||||
sa.ForeignKeyConstraint(['vendor_id'], ['vendors.id'], ),
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('gtin', 'location', name='uq_stock_gtin_location')
|
||||
)
|
||||
op.create_index('idx_stock_gtin_location', 'stock', ['gtin', 'location'], unique=False)
|
||||
op.create_index(op.f('ix_stock_gtin'), 'stock', ['gtin'], unique=False)
|
||||
op.create_index(op.f('ix_stock_id'), 'stock', ['id'], unique=False)
|
||||
op.create_index(op.f('ix_stock_location'), 'stock', ['location'], unique=False)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_index(op.f('ix_stock_location'), table_name='stock')
|
||||
op.drop_index(op.f('ix_stock_id'), table_name='stock')
|
||||
op.drop_index(op.f('ix_stock_gtin'), table_name='stock')
|
||||
op.drop_index('idx_stock_gtin_location', table_name='stock')
|
||||
op.drop_table('stock')
|
||||
op.drop_index(op.f('ix_vendor_products_id'), table_name='vendor_products')
|
||||
op.drop_index('idx_vendor_product_featured', table_name='vendor_products')
|
||||
op.drop_index('idx_vendor_product_active', table_name='vendor_products')
|
||||
op.drop_table('vendor_products')
|
||||
op.drop_index(op.f('ix_marketplace_import_jobs_vendor_name'), table_name='marketplace_import_jobs')
|
||||
op.drop_index(op.f('ix_marketplace_import_jobs_marketplace'), table_name='marketplace_import_jobs')
|
||||
op.drop_index(op.f('ix_marketplace_import_jobs_id'), table_name='marketplace_import_jobs')
|
||||
op.drop_index('idx_marketplace_import_user_marketplace', table_name='marketplace_import_jobs')
|
||||
op.drop_index('idx_marketplace_import_vendor_status', table_name='marketplace_import_jobs')
|
||||
op.drop_index('idx_marketplace_import_vendor_id', table_name='marketplace_import_jobs')
|
||||
op.drop_table('marketplace_import_jobs')
|
||||
op.drop_index(op.f('ix_vendors_vendor_code'), table_name='vendors')
|
||||
op.drop_index(op.f('ix_vendors_id'), table_name='vendors')
|
||||
op.drop_table('vendors')
|
||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_id'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
||||
op.drop_table('users')
|
||||
op.drop_index(op.f('ix_products_vendor_name'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_product_id'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_marketplace'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_id'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_gtin'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_google_product_category'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_brand'), table_name='products')
|
||||
op.drop_index(op.f('ix_products_availability'), table_name='products')
|
||||
op.drop_index('idx_marketplace_shop', table_name='products')
|
||||
op.drop_index('idx_marketplace_brand', table_name='products')
|
||||
op.drop_table('products')
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user