
- Create FastAPI app structure - Set up SQLAlchemy with SQLite for database management - Implement invoice and invoice item models - Add Alembic for database migrations - Create invoice generation and retrieval API endpoints - Add health check endpoint - Set up Ruff for linting - Update README with project details
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
"""Initial database tables
|
|
|
|
Revision ID: ef0aaab3a275
|
|
Revises:
|
|
Create Date: 2023-07-20 10:00:00.000000
|
|
|
|
"""
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = 'ef0aaab3a275'
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.create_table('invoices',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('invoice_number', sa.String(length=255), nullable=False),
|
|
sa.Column('date_created', sa.DateTime(), nullable=False),
|
|
sa.Column('due_date', sa.DateTime(), nullable=False),
|
|
sa.Column('customer_name', sa.String(length=255), nullable=False),
|
|
sa.Column('customer_email', sa.String(length=255), nullable=True),
|
|
sa.Column('customer_address', sa.Text(), nullable=True),
|
|
sa.Column('total_amount', sa.Float(), nullable=False),
|
|
sa.Column('status', sa.String(length=50), nullable=False),
|
|
sa.Column('notes', sa.Text(), nullable=True),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_invoices_id'), 'invoices', ['id'], unique=False)
|
|
op.create_index(op.f('ix_invoices_invoice_number'), 'invoices', ['invoice_number'], unique=True)
|
|
|
|
op.create_table('invoice_items',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('invoice_id', sa.Integer(), nullable=False),
|
|
sa.Column('description', sa.String(length=255), nullable=False),
|
|
sa.Column('quantity', sa.Float(), nullable=False),
|
|
sa.Column('unit_price', sa.Float(), nullable=False),
|
|
sa.Column('amount', sa.Float(), nullable=False),
|
|
sa.ForeignKeyConstraint(['invoice_id'], ['invoices.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_invoice_items_id'), 'invoice_items', ['id'], unique=False)
|
|
# ### end Alembic commands ###
|
|
|
|
|
|
def downgrade() -> None:
|
|
# ### commands auto generated by Alembic - please adjust! ###
|
|
op.drop_index(op.f('ix_invoice_items_id'), table_name='invoice_items')
|
|
op.drop_table('invoice_items')
|
|
op.drop_index(op.f('ix_invoices_invoice_number'), table_name='invoices')
|
|
op.drop_index(op.f('ix_invoices_id'), table_name='invoices')
|
|
op.drop_table('invoices')
|
|
# ### end Alembic commands ### |