
- Set up FastAPI application with CORS support - Configure SQLite database connection - Create database models for users, clients, invoices, and line items - Set up Alembic for database migrations - Implement JWT-based authentication system - Create basic CRUD endpoints for users, clients, and invoices - Add PDF generation functionality - Implement activity logging - Update README with project information
98 lines
4.1 KiB
Python
98 lines
4.1 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 1a2b3c4d5e6f
|
|
Revises:
|
|
Create Date: 2023-11-01 00:00:00.000000
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '1a2b3c4d5e6f'
|
|
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:
|
|
# Create user table
|
|
op.create_table(
|
|
'user',
|
|
sa.Column('id', sa.String(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('hashed_password', sa.String(), nullable=False),
|
|
sa.Column('full_name', sa.String(), nullable=True),
|
|
sa.Column('is_active', sa.Boolean(), nullable=True),
|
|
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.String(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=False),
|
|
sa.Column('email', sa.String(), nullable=False),
|
|
sa.Column('company', sa.String(), nullable=True),
|
|
sa.Column('address', sa.String(), nullable=True),
|
|
sa.Column('phone', sa.String(), nullable=True),
|
|
sa.Column('user_id', sa.String(), nullable=False),
|
|
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE'),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_client_email'), 'client', ['email'], unique=False)
|
|
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.String(), nullable=False),
|
|
sa.Column('invoice_number', sa.String(), nullable=False),
|
|
sa.Column('status', sa.Enum('DRAFT', 'SENT', 'PAID', 'OVERDUE', 'CANCELLED', name='invoicestatus'), nullable=False),
|
|
sa.Column('issued_date', sa.Date(), nullable=False),
|
|
sa.Column('due_date', sa.Date(), nullable=False),
|
|
sa.Column('client_id', sa.String(), nullable=False),
|
|
sa.Column('user_id', sa.String(), nullable=False),
|
|
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(['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.String(), 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('invoice_id', sa.String(), 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)
|
|
|
|
|
|
def downgrade() -> None:
|
|
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_index(op.f('ix_client_email'), table_name='client')
|
|
op.drop_table('client')
|
|
op.drop_index(op.f('ix_user_id'), table_name='user')
|
|
op.drop_index(op.f('ix_user_email'), table_name='user')
|
|
op.drop_table('user') |