fix: migrations to make it postgresql compatible.#2281
fix: migrations to make it postgresql compatible.#2281ormsbee merged 1 commit intoopenedx:masterfrom
Conversation
|
Thanks for the pull request, @qasimgulzar! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
|
@ormsbee could you please approve the workflow execution? |
|
@qasimgulzar: @iloveagent57 said that he could take a look at this one. |
8c0641b to
3516afa
Compare
|
@qasimgulzar - just flagging some failing checks here. |
|
I will take care of it |
88112fd to
3e30cce
Compare
|
Hi @openedx/2u-enterprise! Would someone be able to take a look at this? |
3e30cce to
7496e15
Compare
Friendly ping on this @openedx/enterprise-titans @openedx/2u-enterprise |
ormsbee
left a comment
There was a problem hiding this comment.
Some questions and a few minor (optional) nit suggestions.
| ] | ||
| ), | ||
| ] | ||
| if 'postgresql' in db_engine: |
There was a problem hiding this comment.
Nit: I think this would read a bit easier if it was in an "elif" so that each set of operations is at the same indentation level, i.e.:
if 'sqlite3' in db_engine:
# ...
elif 'postgresql' in db_engine:
# ....
else:
# ...There was a problem hiding this comment.
I would agree it make sense.
| ], | ||
| database_operations=[ | ||
| migrations.RunSQL(sql=""" | ||
| CREATE INDEX cornerstone_cldta_85936b55_idx |
There was a problem hiding this comment.
Question: Why not CREATE INDEX CONCURRENTLY here?
There was a problem hiding this comment.
I believe it will be fresh start of database if anyone will be choosing to go with Postgresql and there will be no pre-populated data. However If I use CONCURRENTLY there is a potential if could have error in background which is very unlikely but there is a chance. So I believe it will only add complexity with no benefits
| ], | ||
| database_operations=[ | ||
| migrations.RunSQL(sql=""" | ||
| CREATE INDEX degreed_dldta_85936b55_idx |
There was a problem hiding this comment.
Question: Why not CREATE INDEX CONCURRENTLY here?
There was a problem hiding this comment.
I believe it will be fresh start of database if anyone will be choosing to go with Postgresql and there will be no pre-populated data. However If I use CONCURRENTLY there is a potential if could have error in background which is very unlikely but there is a chance. So I believe it will only add complexity with no benefits
| else: | ||
| operations = [ | ||
| migrations.AlterIndexTogether( | ||
| name='degreed2learnerdatatransmissionaudit', | ||
| index_together={('enterprise_customer_uuid', 'plugin_configuration_id')}, | ||
| ), | ||
| ] |
There was a problem hiding this comment.
I'm confused by this. Why is this here? When would this ever execute for us, if it's not sqlite, postgres, or mysql?
There was a problem hiding this comment.
you are right I might have overthink here I can cover sqlite with else only.
| CREATE UNIQUE INDEX content_transmission_channel_code_plugin_id_content_id_unique | ||
| ON integrated_channel_contentmetadataitemtransmission (integrated_channel_code, plugin_configuration_id, content_id) | ||
| ALGORITHM=INPLACE LOCK=NONE | ||
| if 'postgresql' in db_engine: |
There was a problem hiding this comment.
Same nit about using elif to reduce indentation here.
| ON moodle_moodlelearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) | ||
| """ | ||
| else: | ||
| raise ValueError("Unsupported database engine") |
There was a problem hiding this comment.
Please add a comment about why it's okay to not account for sqlite3 here.
| options={ | ||
| 'db_table': 'sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5', | ||
| } |
There was a problem hiding this comment.
Question: Why was this change necessary?
There was a problem hiding this comment.
If don't do this change the table name generated in postgresql doesn't match with the table name it generates in mysql. I believe it is because of the make table name length constraints.
The reason of pinning it is as we are using the table name while creating index in subsequent migration.
0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py
| return """ | ||
| CREATE INDEX sapsf_sldta_85936b55_idx | ||
| ON sap_success_factors_sapsuccessfactorslearnerdatatransmission3ce5 (enterprise_customer_uuid, plugin_configuration_id) | ||
| """ |
There was a problem hiding this comment.
NIt: I think this is okay either way, but if it's only being used once, I think you might as well inline it like you did elsewhere in this PR.
| ON xapi_xapilearnerdatatransmissionaudit (enterprise_customer_uuid, plugin_configuration_id) | ||
| ALGORITHM=INPLACE LOCK=NONE | ||
| """, reverse_sql=""" | ||
| migrations.RunSQL(sql=generate_index_sql(db_engine), reverse_sql=""" |
There was a problem hiding this comment.
Nit: I think this is okay either way, but if it's only being used once, I think you might as well inline it like you did elsewhere in this PR.
|
@ormsbee I had accommodated your feedback please give it a look again. Also I have responded to few of your questions. |
7d83fc3 to
3531071
Compare
|
@openedx/2u-enterprise: I'm planning to merge this tomorrow. Please let me know if anyone wants to look it over before I do so. Thank you. |
|
@ormsbee could you please approve the tests again? |
|
@ormsbee could you please approve the workflows now? |
|
@qasimgulzar @ormsbee approved by enterprise, workflows are running now. |
|
@qasimgulzar could you squash the commits, add a CHANGELOG entry, and bump the version, please, and then this will be ready to merge. Thanks! |
|
@iloveagent57 sure I will do it today |
d9bb855 to
71abea6
Compare
|
@iloveagent57 I just pushed these changes.
|
Summary
This pull request includes updates to several migration files across different integrated channels to handle database-specific operations for creating and dropping indexes. The changes ensure compatibility with various database engines, including SQLite, PostgreSQL, and MySQL.
Key Changes:
Database-Specific Index Handling:
integrated_channels/blackboard/migrations/0013_alter_blackboardlearnerdatatransmissionaudit_index_together.py.integrated_channels/canvas/migrations/0028_alter_canvaslearnerdatatransmissionaudit_index_together.py[1]integrated_channels/cornerstone/migrations/0025_alter_cornerstonelearnerdatatransmissionaudit_index_together.py[2]integrated_channels/degreed/migrations/0027_alter_degreedlearnerdatatransmissionaudit_index_together.py[3] andintegrated_channels/degreed2/migrations/0019_alter_degreed2learnerdatatransmissionaudit_index_together.py[4].Refactoring for Index SQL Generation:
integrated_channels/moodle/migrations/0023_alter_moodlelearnerdatatransmissionaudit_index_together.py.integrated_channels/sap_success_factors/migrations/0011_alter_sapsuccessfactorslearnerdatatransmissionaudit_index_together.py.Table Name Specification:
db_tablespecification to theMetaclass in the model to ensure the correct table name is used inintegrated_channels/sap_success_factors/models.py.These changes improve the robustness and compatibility of the migration scripts across different database backends.