Automated Action 27c9268a6a Implement HR platform backend with FastAPI and SQLite
- Set up project structure with FastAPI framework
- Create database models for users, employees, departments, and job titles
- Implement JWT authentication and authorization system
- Set up SQLite database with SQLAlchemy ORM
- Add Alembic migrations for database versioning
- Create CRUD API endpoints for employee management
- Implement category-based search functionality
- Add OpenAPI documentation and health check endpoint
- Update README with comprehensive setup and usage instructions
2025-06-03 01:18:41 +00:00

111 lines
5.0 KiB
Python

"""Initial tables
Revision ID: 001
Revises:
Create Date: 2023-10-30 12: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() -> 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.Column('is_superuser', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_email'), 'user', ['email'], unique=True)
op.create_index(op.f('ix_user_full_name'), 'user', ['full_name'], unique=False)
op.create_index(op.f('ix_user_id'), 'user', ['id'], unique=False)
# Create department table
op.create_table(
'department',
sa.Column('id', sa.String(), nullable=False),
sa.Column('name', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_department_id'), 'department', ['id'], unique=False)
op.create_index(op.f('ix_department_name'), 'department', ['name'], unique=True)
# Create job_title table
op.create_table(
'jobtitle',
sa.Column('id', sa.String(), nullable=False),
sa.Column('title', sa.String(), nullable=False),
sa.Column('description', sa.Text(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_jobtitle_id'), 'jobtitle', ['id'], unique=False)
op.create_index(op.f('ix_jobtitle_title'), 'jobtitle', ['title'], unique=True)
# Create employee table
op.create_table(
'employee',
sa.Column('id', sa.String(), nullable=False),
sa.Column('first_name', sa.String(), nullable=False),
sa.Column('last_name', sa.String(), nullable=False),
sa.Column('email', sa.String(), nullable=False),
sa.Column('phone', sa.String(), nullable=True),
sa.Column('hire_date', sa.Date(), nullable=False),
sa.Column('birth_date', sa.Date(), nullable=True),
sa.Column('address', sa.Text(), nullable=True),
sa.Column('department_id', sa.String(), nullable=False),
sa.Column('job_title_id', sa.String(), nullable=False),
sa.Column('manager_id', sa.String(), nullable=True),
sa.Column('skills', sa.Text(), nullable=True),
sa.Column('categories', sa.Text(), nullable=True),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=True),
sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
sa.ForeignKeyConstraint(['department_id'], ['department.id'], ),
sa.ForeignKeyConstraint(['job_title_id'], ['jobtitle.id'], ),
sa.ForeignKeyConstraint(['manager_id'], ['employee.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_employee_email'), 'employee', ['email'], unique=True)
op.create_index(op.f('ix_employee_first_name'), 'employee', ['first_name'], unique=False)
op.create_index(op.f('ix_employee_id'), 'employee', ['id'], unique=False)
op.create_index(op.f('ix_employee_last_name'), 'employee', ['last_name'], unique=False)
def downgrade() -> None:
op.drop_index(op.f('ix_employee_last_name'), table_name='employee')
op.drop_index(op.f('ix_employee_id'), table_name='employee')
op.drop_index(op.f('ix_employee_first_name'), table_name='employee')
op.drop_index(op.f('ix_employee_email'), table_name='employee')
op.drop_table('employee')
op.drop_index(op.f('ix_jobtitle_title'), table_name='jobtitle')
op.drop_index(op.f('ix_jobtitle_id'), table_name='jobtitle')
op.drop_table('jobtitle')
op.drop_index(op.f('ix_department_name'), table_name='department')
op.drop_index(op.f('ix_department_id'), table_name='department')
op.drop_table('department')
op.drop_index(op.f('ix_user_id'), table_name='user')
op.drop_index(op.f('ix_user_full_name'), table_name='user')
op.drop_index(op.f('ix_user_email'), table_name='user')
op.drop_table('user')