Skip to content
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

Add database schema update and database migration logic #520

Merged
merged 12 commits into from
May 28, 2024

Conversation

andrii-i
Copy link
Collaborator

@andrii-i andrii-i commented May 20, 2024

Add database schema update and database migration logic, test cases.

With this PR, if database schema is extended between versions, schema is automatically updated and relevant tables are altered accordingly preventing errors. Note that database migration logic currently only covers extension of the tables as in addition of new columns.

Fixes #519.

@andrii-i andrii-i added enhancement New feature or request Testing labels May 20, 2024
@andrii-i andrii-i closed this May 21, 2024
@andrii-i andrii-i reopened this May 21, 2024
@andrii-i andrii-i force-pushed the db_migration branch 2 times, most recently from 7065131 to 37e7682 Compare May 21, 2024 20:11
@andrii-i andrii-i marked this pull request as ready for review May 21, 2024 20:18
@andrii-i andrii-i changed the title Add DB migration logic Add database schema update and databse migration logic May 21, 2024
@andrii-i andrii-i changed the title Add database schema update and databse migration logic Add database schema update and database migration logic May 21, 2024
dlqqq
dlqqq previously requested changes May 23, 2024
Copy link
Collaborator

@dlqqq dlqqq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrii-i Thank you for working on this! Left some comments below.

@@ -104,6 +105,7 @@ class Job(CommonColumns, Base):

class JobDefinition(CommonColumns, Base):
__tablename__ = "job_definitions"
__table_args__ = {"extend_existing": True}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to do some testing to understand why this is necessary if we are defining update_db_schema(). Essentially, this argument is needed to extend the table metadata (e.g. column names & types) associated with the table. If this line is omitted in test_orm.py, the test fails with the error:

sqlalchemy.exc.InvalidRequestError: Table 'jobs' is already defined for this MetaData instance.  Specify 'extend_existing=True' to redefine options and columns on an existing Table object.

So both the table migration (defined in update_db_schema()) and table metadata migration (defined here by setting __table_args__ = {"extend_existing": True}) must be performed when a new column is added. 😵

No action needed. I just felt it was necessary to call this out to other readers in this review.

jupyter_scheduler/orm.py Outdated Show resolved Hide resolved
jupyter_scheduler/orm.py Outdated Show resolved Hide resolved
@andrii-i andrii-i dismissed dlqqq’s stale review May 25, 2024 00:05

@dlqqq is not available until May 30. All comments were implemented except the request to parametrize identifiers as decided during discussion on the topic with @dlqqq. Details in the comment: #520 (comment).

jupyter_scheduler/orm.py Outdated Show resolved Hide resolved
jupyter_scheduler/orm.py Outdated Show resolved Hide resolved
jupyter_scheduler/orm.py Show resolved Hide resolved
@andrii-i andrii-i requested a review from 3coins May 28, 2024 22:50
Copy link
Collaborator

@3coins 3coins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 🚀

@andrii-i andrii-i merged commit 5b55901 into jupyter-server:main May 28, 2024
6 checks passed
@andrii-i andrii-i deleted the db_migration branch May 28, 2024 23:54
@andrii-i
Copy link
Collaborator Author

Thank you everyone for reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migration scripts? no such column: jobs.package_input_folder
4 participants