"""Initial schema for sales service Revision ID: 00001 Revises: Create Date: 2025-09-30 18:00:00.0000 """ from alembic import op import sqlalchemy as sa from sqlalchemy.dialects import postgresql # revision identifiers, used by Alembic. revision = '00001' down_revision = None branch_labels = None depends_on = None def upgrade() -> None: op.create_table('sales_transactions', sa.Column('id', sa.UUID(), nullable=False), sa.Column('tenant_id', sa.UUID(), nullable=False), sa.Column('order_id', sa.UUID(), nullable=True), sa.Column('customer_id', sa.UUID(), nullable=True), sa.Column('transaction_type', sa.String(50), nullable=False), sa.Column('payment_method', sa.String(50), nullable=True), sa.Column('total_amount', sa.Float(), nullable=False), sa.Column('tax_amount', sa.Float(), nullable=True), sa.Column('discount_amount', sa.Float(), nullable=True), sa.Column('currency', sa.String(3), nullable=True), sa.Column('status', sa.String(50), nullable=True), sa.Column('transaction_date', sa.DateTime(), nullable=False), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True), sa.Column('updated_at', sa.DateTime(), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_sales_transactions_tenant_id'), 'sales_transactions', ['tenant_id'], unique=False) op.create_index(op.f('ix_sales_transactions_order_id'), 'sales_transactions', ['order_id'], unique=False) op.create_index(op.f('ix_sales_transactions_customer_id'), 'sales_transactions', ['customer_id'], unique=False) op.create_index(op.f('ix_sales_transactions_transaction_type'), 'sales_transactions', ['transaction_type'], unique=False) op.create_index(op.f('ix_sales_transactions_status'), 'sales_transactions', ['status'], unique=False) op.create_index(op.f('ix_sales_transactions_transaction_date'), 'sales_transactions', ['transaction_date'], unique=False) op.create_table('sales_reports', sa.Column('id', sa.UUID(), nullable=False), sa.Column('tenant_id', sa.UUID(), nullable=False), sa.Column('report_type', sa.String(100), nullable=False), sa.Column('report_date', sa.Date(), nullable=False), sa.Column('period_start', sa.Date(), nullable=False), sa.Column('period_end', sa.Date(), nullable=False), sa.Column('total_sales', sa.Float(), nullable=False), sa.Column('total_transactions', sa.Integer(), nullable=False), sa.Column('average_transaction_value', sa.Float(), nullable=True), sa.Column('top_products', postgresql.JSON(astext_type=sa.Text()), nullable=True), sa.Column('metrics', postgresql.JSON(astext_type=sa.Text()), nullable=True), sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True), sa.PrimaryKeyConstraint('id') ) op.create_index(op.f('ix_sales_reports_tenant_id'), 'sales_reports', ['tenant_id'], unique=False) op.create_index(op.f('ix_sales_reports_report_type'), 'sales_reports', ['report_type'], unique=False) op.create_index(op.f('ix_sales_reports_report_date'), 'sales_reports', ['report_date'], unique=False) def downgrade() -> None: op.drop_index(op.f('ix_sales_reports_report_date'), table_name='sales_reports') op.drop_index(op.f('ix_sales_reports_report_type'), table_name='sales_reports') op.drop_index(op.f('ix_sales_reports_tenant_id'), table_name='sales_reports') op.drop_table('sales_reports') op.drop_index(op.f('ix_sales_transactions_transaction_date'), table_name='sales_transactions') op.drop_index(op.f('ix_sales_transactions_status'), table_name='sales_transactions') op.drop_index(op.f('ix_sales_transactions_transaction_type'), table_name='sales_transactions') op.drop_index(op.f('ix_sales_transactions_customer_id'), table_name='sales_transactions') op.drop_index(op.f('ix_sales_transactions_order_id'), table_name='sales_transactions') op.drop_index(op.f('ix_sales_transactions_tenant_id'), table_name='sales_transactions') op.drop_table('sales_transactions')