
- Set up project structure with FastAPI - Implement user authentication system with JWT tokens - Create database models for users, notes, and collections - Set up SQLAlchemy ORM and Alembic migrations - Implement CRUD operations for notes and collections - Add filtering and sorting capabilities for notes - Implement health check endpoint - Update project documentation
90 lines
3.5 KiB
Python
90 lines
3.5 KiB
Python
"""Initial schema
|
|
|
|
Revision ID: 0001
|
|
Revises:
|
|
Create Date: 2023-06-01
|
|
|
|
"""
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision: str = '0001'
|
|
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 users table
|
|
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('is_active', sa.Boolean(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
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)
|
|
|
|
# Create collections table
|
|
op.create_table(
|
|
'collections',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('name', sa.String(), nullable=True),
|
|
sa.Column('description', sa.String(), nullable=True),
|
|
sa.Column('owner_id', sa.Integer(), 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_collections_id'), 'collections', ['id'], unique=False)
|
|
op.create_index(op.f('ix_collections_name'), 'collections', ['name'], unique=False)
|
|
|
|
# Create notes table
|
|
op.create_table(
|
|
'notes',
|
|
sa.Column('id', sa.Integer(), nullable=False),
|
|
sa.Column('title', sa.String(), nullable=True),
|
|
sa.Column('content', sa.Text(), nullable=True),
|
|
sa.Column('is_archived', sa.Boolean(), nullable=True),
|
|
sa.Column('owner_id', sa.Integer(), nullable=True),
|
|
sa.Column('collection_id', sa.Integer(), nullable=True),
|
|
sa.Column('created_at', sa.DateTime(), nullable=True),
|
|
sa.Column('updated_at', sa.DateTime(), nullable=True),
|
|
sa.ForeignKeyConstraint(['collection_id'], ['collections.id'], ),
|
|
sa.ForeignKeyConstraint(['owner_id'], ['users.id'], ),
|
|
sa.PrimaryKeyConstraint('id')
|
|
)
|
|
op.create_index(op.f('ix_notes_created_at'), 'notes', ['created_at'], unique=False)
|
|
op.create_index(op.f('ix_notes_id'), 'notes', ['id'], unique=False)
|
|
op.create_index(op.f('ix_notes_title'), 'notes', ['title'], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
# Drop notes table
|
|
op.drop_index(op.f('ix_notes_title'), table_name='notes')
|
|
op.drop_index(op.f('ix_notes_id'), table_name='notes')
|
|
op.drop_index(op.f('ix_notes_created_at'), table_name='notes')
|
|
op.drop_table('notes')
|
|
|
|
# Drop collections table
|
|
op.drop_index(op.f('ix_collections_name'), table_name='collections')
|
|
op.drop_index(op.f('ix_collections_id'), table_name='collections')
|
|
op.drop_table('collections')
|
|
|
|
# Drop users table
|
|
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')
|