
Features: - User authentication with JWT - Client management with CRUD operations - Invoice generation and management - SQLite database with Alembic migrations - Detailed project documentation
123 lines
5.2 KiB
Python
123 lines
5.2 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2023-07-24 00:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = '001'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade():
|
|
# Create user table
|
|
op.create_table(
|
|
'user',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=False),
|
|
sa.Column('company_name', sa.String(), nullable=True),
|
|
sa.Column('address', sa.String(), nullable=True),
|
|
sa.Column('phone', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), 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_user_email'), 'user', ['email'], unique=True)
|
|
op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False)
|
|
|
|
# Create client table
|
|
op.create_table(
|
|
'client',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('company_name', sa.String(), nullable=True),
|
|
sa.Column('address', sa.String(), nullable=True),
|
|
sa.Column('phone', sa.String(), nullable=True),
|
|
sa.Column('notes', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_client_id'), 'client', ['id'], unique=False)
|
|
op.create_index(op.f('ix_client_name'), 'client', ['name'], unique=False)
|
|
|
|
# Create invoice table
|
|
op.create_table(
|
|
'invoice',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('client_id', sa.Integer(), nullable=False),
|
|
sa.Column('invoice_number', sa.String(), nullable=False),
|
|
sa.Column('status', sa.String(), nullable=False),
|
|
sa.Column('issued_date', sa.Date(), nullable=True),
|
|
sa.Column('due_date', sa.Date(), nullable=True),
|
|
sa.Column('notes', sa.Text(), nullable=True),
|
|
sa.Column('total_amount', sa.Float(), nullable=False),
|
|
sa.Column('pdf_path', sa.String(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['client_id'], ['client.id'], ondelete='CASCADE'),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_invoice_id'), 'invoice', ['id'], unique=False)
|
|
op.create_index(op.f('ix_invoice_invoice_number'), 'invoice', ['invoice_number'], unique=False)
|
|
|
|
# Create invoice_item table
|
|
op.create_table(
|
|
'invoiceitem',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('invoice_id', sa.Integer(), nullable=False),
|
|
sa.Column('description', sa.String(), nullable=False),
|
|
sa.Column('quantity', sa.Float(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('created_at', sa.DateTime(), nullable=False),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['invoice_id'], ['invoice.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_invoiceitem_id'), 'invoiceitem', ['id'], unique=False)
|
|
|
|
# Create activity table
|
|
op.create_table(
|
|
'activity',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
sa.Column('action', sa.String(), nullable=False),
|
|
sa.Column('entity_type', sa.String(), nullable=False),
|
|
sa.Column('entity_id', sa.Integer(), nullable=True),
|
|
sa.Column('details', sa.Text(), nullable=True),
|
|
sa.Column('timestamp', sa.DateTime(), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_activity_id'), 'activity', ['id'], unique=False)
|
|
|
|
|
|
def downgrade():
|
|
op.drop_index(op.f('ix_activity_id'), table_name='activity')
|
|
op.drop_table('activity')
|
|
op.drop_index(op.f('ix_invoiceitem_id'), table_name='invoiceitem')
|
|
op.drop_table('invoiceitem')
|
|
op.drop_index(op.f('ix_invoice_invoice_number'), table_name='invoice')
|
|
op.drop_index(op.f('ix_invoice_id'), table_name='invoice')
|
|
op.drop_table('invoice')
|
|
op.drop_index(op.f('ix_client_name'), table_name='client')
|
|
op.drop_index(op.f('ix_client_id'), table_name='client')
|
|
op.drop_table('client')
|
|
op.drop_index(op.f('ix_user_email'), table_name='user')
|
|
op.drop_index(op.f('ix_user_id'), table_name='user')
|
|
op.drop_table('user') |