Automated Action 5935f302dc Create Small Business Inventory Management System with FastAPI and SQLite
- Set up project structure and FastAPI application
- Create database models with SQLAlchemy
- Implement authentication with JWT
- Add CRUD operations for products, inventory, categories
- Implement purchase order and sales functionality
- Create reporting endpoints
- Set up Alembic for database migrations
- Add comprehensive documentation in README.md
2025-05-16 08:53:15 +00:00

51 lines
1.3 KiB
Python

"""Add admin user
Revision ID: 002
Revises: 001
Create Date: 2023-08-12 00:01:00.000000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.sql import table, column
import datetime
from passlib.context import CryptContext
# revision identifiers, used by Alembic.
revision = '002'
down_revision = '001'
branch_labels = None
depends_on = None
def upgrade():
# Create a pwd_context object for password hashing
pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto")
# Define the user table for inserting data
user_table = table('user',
column('id', sa.Integer),
column('full_name', sa.String),
column('email', sa.String),
column('hashed_password', sa.String),
column('is_active', sa.Boolean),
column('is_admin', sa.Boolean)
)
# Insert admin user with hashed password
op.bulk_insert(user_table,
[
{
'full_name': 'Admin User',
'email': 'admin@example.com',
'hashed_password': pwd_context.hash('admin123'), # Default password, should be changed
'is_active': True,
'is_admin': True
}
]
)
def downgrade():
# Remove the admin user - find by email
op.execute("DELETE FROM user WHERE email = 'admin@example.com'")