Gurucool_Test / migrations /versions /c6c1acf911ad_migrations.py
ashwinR's picture
Upload 245 files
b7a7f32
raw
history blame
13.9 kB
"""migrations
Revision ID: c6c1acf911ad
Revises:
Create Date: 2023-07-29 04:34:07.378969
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'c6c1acf911ad'
down_revision = None
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('school',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=False),
sa.Column('address', sa.String(length=64), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('userpermission',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_userpermission_name'), 'userpermission', ['name'], unique=True)
op.create_table('department',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=128), nullable=True),
sa.Column('school_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['school_id'], ['school.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('course',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('course_code', sa.String(), nullable=True),
sa.Column('course_name', sa.String(length=128), nullable=False),
sa.Column('course_credit', sa.SmallInteger(), nullable=True),
sa.Column('department_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['department_id'], ['department.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_course_course_code'), 'course', ['course_code'], unique=True)
op.create_table('program',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=64), nullable=True),
sa.Column('department_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['department_id'], ['department.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('assignment',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('due_date', sa.DateTime(), nullable=True),
sa.Column('marks', sa.Integer(), nullable=True),
sa.Column('title', sa.String(length=2048), nullable=True),
sa.Column('contents', sa.String(length=32168), nullable=True),
sa.Column('files', sa.ARRAY(sa.JSON()), nullable=True),
sa.Column('course_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('group',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('program_id', sa.Integer(), nullable=True),
sa.Column('sem', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['program_id'], ['program.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('quiz',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('title', sa.String(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.Column('is_randomized', sa.Boolean(), nullable=True),
sa.Column('display_individual', sa.Boolean(), nullable=True),
sa.Column('total_marks', sa.Integer(), nullable=True),
sa.Column('course_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('assignment_group_association',
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('assignment_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assignment_id'], ['assignment.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='CASCADE')
)
op.create_table('class_session',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('end_time', sa.DateTime(), nullable=True),
sa.Column('course_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('description', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ondelete='cascade'),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('group_course_association',
sa.Column('course_id', sa.Integer(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='CASCADE')
)
op.create_table('group_quiz_association',
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('quiz_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['quiz_id'], ['quiz.id'], ondelete='CASCADE')
)
op.create_table('quiz_question',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('question_text', sa.String(), nullable=True),
sa.Column('question_image', sa.ARRAY(sa.String()), nullable=True),
sa.Column('options', sa.JSON(), nullable=False),
sa.Column('marks', sa.Integer(), nullable=True),
sa.Column('answer', sa.ARRAY(sa.Integer()), nullable=True),
sa.Column('quiz_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['quiz_id'], ['quiz.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('profile_image', sa.String(length=100), nullable=True),
sa.Column('full_name', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=False),
sa.Column('two_fa_secret', sa.String(), nullable=True),
sa.Column('roll', sa.SmallInteger(), nullable=True),
sa.Column('group_id', sa.Integer(), nullable=True),
sa.Column('teacher_department_id', sa.Integer(), nullable=True),
sa.Column('dob', sa.Date(), nullable=False),
sa.Column('address', sa.String(length=128), nullable=False),
sa.Column('contact_number', sa.String(length=32), nullable=False),
sa.Column('hashed_password', sa.String(), nullable=False),
sa.Column('is_active', sa.Boolean(), nullable=True),
sa.Column('user_type', sa.SmallInteger(), nullable=False),
sa.Column('join_year', sa.SmallInteger(), nullable=True),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='cascade'),
sa.ForeignKeyConstraint(['teacher_department_id'], ['department.id'], ondelete='SET NULL'),
sa.PrimaryKeyConstraint('id')
)
op.create_index(op.f('ix_user_contact_number'), 'user', ['contact_number'], unique=False)
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)
op.create_index(op.f('ix_user_user_type'), 'user', ['user_type'], unique=False)
op.create_table('assignment_instructor_association',
sa.Column('instructor_id', sa.Integer(), nullable=True),
sa.Column('assignment_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assignment_id'], ['assignment.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['instructor_id'], ['user.id'], ondelete='CASCADE')
)
op.create_table('assignment_upload',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('submission_date', sa.DateTime(), nullable=True),
sa.Column('marks_obtained', sa.Integer(), nullable=True),
sa.Column('files', sa.ARRAY(sa.JSON()), nullable=True),
sa.Column('assignment_id', sa.Integer(), nullable=True),
sa.Column('student_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['assignment_id'], ['assignment.id'], ondelete='cascade'),
sa.ForeignKeyConstraint(['student_id'], ['user.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('assignment_id', 'student_id', name='__student_assignment_uc')
)
op.create_table('attendant_class_session_association',
sa.Column('class_session_id', sa.Integer(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['class_session_id'], ['class_session.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE')
)
op.create_table('file',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(), nullable=True),
sa.Column('path', sa.String(), nullable=True),
sa.Column('file_type', sa.String(), nullable=True),
sa.Column('uploaded_datetime', sa.DateTime(), nullable=True),
sa.Column('class_session_id', sa.Integer(), nullable=False),
sa.Column('description', sa.String(), nullable=True),
sa.ForeignKeyConstraint(['class_session_id'], ['class_session.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('instructor_quiz_association',
sa.Column('instructor_id', sa.Integer(), nullable=True),
sa.Column('quiz_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['instructor_id'], ['user.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['quiz_id'], ['quiz.id'], ondelete='CASCADE')
)
op.create_table('personalnote',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('last_updated_time', sa.DateTime(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('tags', sa.ARRAY(sa.String(length=32)), nullable=True),
sa.Column('title', sa.String(length=128), nullable=True),
sa.Column('content', sa.String(length=32768), nullable=True),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('quiz_answer',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('marks_obtained', sa.Integer(), nullable=True),
sa.Column('options_selected', sa.JSON(), nullable=True),
sa.Column('quiz_id', sa.Integer(), nullable=True),
sa.Column('student_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['quiz_id'], ['quiz.id'], ondelete='cascade'),
sa.ForeignKeyConstraint(['student_id'], ['user.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id'),
sa.UniqueConstraint('quiz_id', 'student_id', name='__student_quiz_uc')
)
op.create_table('teacher_group_course_association',
sa.Column('teacher_id', sa.Integer(), nullable=False),
sa.Column('group_id', sa.Integer(), nullable=False),
sa.Column('course_id', sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(['course_id'], ['course.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['teacher_id'], ['user.id'], ondelete='CASCADE'),
sa.PrimaryKeyConstraint('teacher_id', 'group_id')
)
op.create_table('teachernote',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.Column('student_id', sa.Integer(), nullable=True),
sa.Column('message', sa.String(length=512), nullable=True),
sa.ForeignKeyConstraint(['student_id'], ['user.id'], ondelete='cascade'),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('user_class_session_association',
sa.Column('class_session_id', sa.Integer(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['class_session_id'], ['class_session.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE')
)
op.create_table('user_permission_association',
sa.Column('permission_id', sa.Integer(), nullable=True),
sa.Column('user_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['permission_id'], ['userpermission.id'], ondelete='CASCADE'),
sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='CASCADE')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('user_permission_association')
op.drop_table('user_class_session_association')
op.drop_table('teachernote')
op.drop_table('teacher_group_course_association')
op.drop_table('quiz_answer')
op.drop_table('personalnote')
op.drop_table('instructor_quiz_association')
op.drop_table('file')
op.drop_table('attendant_class_session_association')
op.drop_table('assignment_upload')
op.drop_table('assignment_instructor_association')
op.drop_index(op.f('ix_user_user_type'), table_name='user')
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_index(op.f('ix_user_contact_number'), table_name='user')
op.drop_table('user')
op.drop_table('quiz_question')
op.drop_table('group_quiz_association')
op.drop_table('group_course_association')
op.drop_table('class_session')
op.drop_table('assignment_group_association')
op.drop_table('quiz')
op.drop_table('group')
op.drop_table('assignment')
op.drop_table('program')
op.drop_index(op.f('ix_course_course_code'), table_name='course')
op.drop_table('course')
op.drop_table('department')
op.drop_index(op.f('ix_userpermission_name'), table_name='userpermission')
op.drop_table('userpermission')
op.drop_table('school')
# ### end Alembic commands ###