diff --git a/alembic/versions/20250327_211525_c3eff1ec_create_user.py b/alembic/versions/20250327_211525_c3eff1ec_create_user.py new file mode 100644 index 0000000..9b3ad20 --- /dev/null +++ b/alembic/versions/20250327_211525_c3eff1ec_create_user.py @@ -0,0 +1,45 @@ +"""create users table + +Revision ID: a1b2c3d4e5f6 +Revises: +Create Date: 2023-01-01 12:00:00.000000 +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql +from sqlalchemy import func, Enum +import uuid + +revision = 'a1b2c3d4e5f6' +down_revision = None +branch_labels = None +depends_on = None + +def upgrade(): + user_roles = postgresql.ENUM('student', 'teacher', 'admin', name='user_roles') + user_roles.create(op.get_bind()) + + op.create_table( + 'users', + sa.Column('id', sa.String(), primary_key=True, default=lambda: str(uuid.uuid4())), + sa.Column('first_name', sa.String(50)), + sa.Column('last_name', sa.String(50)), + sa.Column('email', sa.String(100)), + sa.Column('password', sa.String(), nullable=False), + sa.Column('role', sa.Enum('student', 'teacher', 'admin', name='user_roles')), + sa.Column('phone_number', sa.String(20)), + sa.Column('address', sa.String(200)), + sa.Column('date_of_birth', sa.DateTime()), + sa.Column('profile_picture', sa.String()), + sa.Column('is_active', sa.Boolean(), default=True), + sa.Column('last_login', sa.DateTime()), + sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()), + sa.Column('updated_at', sa.DateTime(), server_default=sa.func.now(), onupdate=sa.func.now()), + ) + + op.create_index('ix_users_email', 'users', ['email'], unique=True) + +def downgrade(): + op.drop_index('ix_users_email', 'users') + op.drop_table('users') + op.execute('DROP TYPE user_roles') \ No newline at end of file