Skip to content
Prev Previous commit
Next Next commit
Merge branch 'master' into edit-profile
  • Loading branch information
orronai authored Oct 19, 2021
commit f647f9e221e2372513ee73dddf0aab8aa499cd4b
23 changes: 18 additions & 5 deletions lms/lmsdb/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,22 +328,35 @@ def _avatar_migration() -> bool:
return True


def is_tables_exists(tables: Union[Model, Iterable[Model]]) -> bool:
if not isinstance(tables, (tuple, list)):
tables = (tables,)

return all(
models.database.table_exists(table.__name__.lower())
for table in tables
)


def get_new_tables(tables: Iterable[Model]) -> List[Model]:
return [table for table in tables if not is_tables_exists(table)]



def main():
with models.database.connection_context():
new_tables = get_new_tables(models.ALL_MODELS)
models.database.create_tables(new_tables, safe=True)

_add_exercise_course_id_and_number_columns_constraint()

if models.database.table_exists(models.User.__name__.lower()):
_api_keys_migration()
_last_course_viewed_migration()
_uuid_migration()
_avatar_migration()
_last_status_view_migration()
_assessment_migration()

_api_keys_migration()
_last_course_viewed_migration()
_uuid_migration()
_avatar_migration()

_add_user_course_constaint()

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.