-
Notifications
You must be signed in to change notification settings - Fork 60
Migrate to SQLModel and improve relationship loading #4547
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
a6462f4
Add basic relationship loading strategies
kitsuta d9b6210
Fix server-side pagination 500 errors
kitsuta 0a0d4db
Add missing default API testing functions
kitsuta bdd9a5d
Fix page tracking for budget pages
kitsuta 0688a1e
Add and fix missing functions from residue
kitsuta 6c9c069
Fix basic relationship loading for most pages
kitsuta 7938b86
Basic SQLModel conversion
kitsuta c3a3ded
SQLModel now working for server startup
kitsuta 119e6d6
Completely rewrite relationships in SQLModel
kitsuta 32e3eea
Fix models for migration generation
kitsuta 8712e07
Dial in SQLModel overhaul
kitsuta 62ad27c
Fix prereg and stop relationship raising
kitsuta bbe397b
Remove extra promo_code_word migration
kitsuta 7bfaab6
Last prereg fixes (hopefully)
kitsuta 180f374
Remove extraneous session = Session() line
kitsuta 735f941
More fixes for temporary attributes
kitsuta 8ad5f82
Fix erroneous "is_table" arguments
kitsuta 9bbcbbc
Fix issue with setting ribbons
kitsuta e7235c5
Fix plugin columns
kitsuta af4da76
Stop auto-creating tables
kitsuta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
alembic/versions/3d942ce689fc_add_missing_columns_from_sqlalchemy_.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Add missing columns from SQLAlchemy upgrade | ||
|
|
||
| Revision ID: 3d942ce689fc | ||
| Revises: 5a0e898174d4 | ||
| Create Date: 2026-02-05 16:34:19.803186 | ||
|
|
||
| """ | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = '3d942ce689fc' | ||
| down_revision = '5a0e898174d4' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
|
|
||
| try: | ||
| is_sqlite = op.get_context().dialect.name == 'sqlite' | ||
| except Exception: | ||
| is_sqlite = False | ||
|
|
||
| if is_sqlite: | ||
| op.get_context().connection.execute('PRAGMA foreign_keys=ON;') | ||
| utcnow_server_default = "(datetime('now', 'utc'))" | ||
| else: | ||
| utcnow_server_default = "timezone('utc', current_timestamp)" | ||
|
|
||
| def sqlite_column_reflect_listener(inspector, table, column_info): | ||
| """Adds parenthesis around SQLite datetime defaults for utcnow.""" | ||
| if column_info['default'] == "datetime('now', 'utc')": | ||
| column_info['default'] = utcnow_server_default | ||
|
|
||
| sqlite_reflect_kwargs = { | ||
| 'listeners': [('column_reflect', sqlite_column_reflect_listener)] | ||
| } | ||
|
|
||
| # =========================================================================== | ||
| # HOWTO: Handle alter statements in SQLite | ||
| # | ||
| # def upgrade(): | ||
| # if is_sqlite: | ||
| # with op.batch_alter_table('table_name', reflect_kwargs=sqlite_reflect_kwargs) as batch_op: | ||
| # batch_op.alter_column('column_name', type_=sa.Unicode(), server_default='', nullable=False) | ||
| # else: | ||
| # op.alter_column('table_name', 'column_name', type_=sa.Unicode(), server_default='', nullable=False) | ||
| # | ||
| # =========================================================================== | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.add_column('panel_applicant', sa.Column('social_media_info', sa.String(), server_default='', nullable=False)) | ||
| op.drop_column('panel_applicant', 'social_media') | ||
| op.drop_index(op.f('uq_promo_code_word_normalized_word_part_of_speech'), table_name='promo_code_word') | ||
| op.create_index('uq_promo_code_word_normalized_word_part_of_speech', 'promo_code_word', [sa.literal_column('lower(trim(word))'), 'part_of_speech'], unique=True) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_index('uq_promo_code_word_normalized_word_part_of_speech', table_name='promo_code_word') | ||
| op.create_index(op.f('uq_promo_code_word_normalized_word_part_of_speech'), 'promo_code_word', [sa.literal_column('lower(TRIM(BOTH FROM word))'), 'part_of_speech'], unique=True) | ||
| op.add_column('panel_applicant', sa.Column('social_media', postgresql.JSON(astext_type=sa.Text()), server_default=sa.text("'{}'::json"), autoincrement=False, nullable=False)) | ||
| op.drop_column('panel_applicant', 'social_media_info') |
606 changes: 606 additions & 0 deletions
606
alembic/versions/6902e1cceec6_relationships_overhaul.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ | |
|
|
||
| with Session() as session: | ||
| initialize_db() | ||
| session = Session().session | ||
| session = Session() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be called? Shouldn't session already be defined and set to the session by the context manager?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, yea, this must have been an old copy-paste error.