"""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'")