-
Notifications
You must be signed in to change notification settings - Fork 34
Draft: feat: Add column to DB + Migration #377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -338,6 +338,12 @@ def _linter_email_migration(): | |
log.info(f'{new_mail_address} already exists in User') | ||
|
||
|
||
def _add_is_model_solution_column() -> bool: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (complexity): Consider abstracting the column addition into a more generic function. While the added functionality in def _migrate_add_column(model, column_name, column_type): if not column_exists(model, column_name): with models.database.atomic(): migrator = MySQLMigrator(models.database) migrate( migrator.add_column(model._meta.table_name, column_name, column_type()) ) log.info(f"Column {column_name} added to {model._meta.table_name}") else: log.info(f"Column {column_name} already exists in {model._meta.table_name}") This method can then be used for adding any column to any model, reducing the need for specific functions for each migration task. It simplifies the migration process, making the codebase easier to maintain and extend in the future. |
||
Solution = models.Solution | ||
_migrate_column_in_table_if_needed(Solution, Solution.is_model_solution) | ||
return True | ||
Comment on lines
+341
to
+344
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Ensure the return value of The function always returns |
||
|
||
|
||
def is_tables_exists(tables: Union[Model, Iterable[Model]]) -> bool: | ||
if not isinstance(tables, (tuple, list)): | ||
tables = (tables,) | ||
|
@@ -369,6 +375,8 @@ def main(): | |
_add_user_course_constaint() | ||
_linter_email_migration() | ||
|
||
_add_is_model_solution_column() | ||
|
||
models.create_basic_roles() | ||
if models.User.select().count() == 0: | ||
models.create_demo_users() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -624,6 +624,7 @@ class Solution(BaseModel): | |
exercise = ForeignKeyField(Exercise, backref='solutions') | ||
solver = ForeignKeyField(User, backref='solutions') | ||
checker = ForeignKeyField(User, null=True, backref='solutions') | ||
is_key_answer = BooleanField(default=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_clarification): Consider renaming The new column added to the |
||
state = CharField( | ||
choices=STATES.to_choices(), | ||
default=STATES.CREATED.name, | ||
|