Skip to content

Conversation

@qasimgulzar
Copy link
Contributor

@qasimgulzar qasimgulzar commented Nov 4, 2024

Summary

This pull request includes several important changes to improve database migrations and remove the UnsignedBigIntAutoField custom field. The key changes involve modifying SQL commands to support different database engines and ensuring atomic transactions during migrations. The most important changes are summarized below:

Database Migration Improvements:

Field Type Changes:

  • lms/djangoapps/courseware/models.py, lms/djangoapps/courseware/migrations/0001_initial.py, lms/djangoapps/coursewarehistoryextended/models.py, lms/djangoapps/coursewarehistoryextended/migrations/0001_initial.py, lms/djangoapps/grades/models.py, lms/djangoapps/grades/migrations/0001_initial.py: Replaced UnsignedBigIntAutoField with models.BigAutoField to standardize the primary key field types. [1] [2] [3] [4] [5] [6]

Code Cleanup:

These changes ensure better compatibility with different database engines and improve the consistency and maintainability of the codebase.

Subsequent Pull Requests

  1. edx-when
  2. xblock-lti-consumer
  3. edx-enterprise
  4. edx-milestones
  5. openedx-learning

@qasimgulzar qasimgulzar requested a review from a team as a code owner November 4, 2024 08:28
@openedx-webhooks
Copy link

openedx-webhooks commented Nov 4, 2024

Thanks for the pull request, @qasimgulzar!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

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 approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To 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:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where 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:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Nov 4, 2024
@qasimgulzar qasimgulzar force-pushed the qasim/postgres branch 3 times, most recently from b8bc93e to eae8dd3 Compare November 5, 2024 14:23
@qasimgulzar
Copy link
Contributor Author

@ormsbee I am waiting on it's subsequent PRs to be merged before moving ahead for further implementations.

@qasimgulzar
Copy link
Contributor Author

Update.-.1.1.-.min.mov

@qasimgulzar
Copy link
Contributor Author

I will take care of the broken tests

@qasimgulzar
Copy link
Contributor Author

@ormsbee can we manage review for the subsequent PRs?

@qasimgulzar qasimgulzar force-pushed the qasim/postgres branch 2 times, most recently from 005c29d to 6d0f777 Compare November 26, 2024 06:28
@qasimgulzar
Copy link
Contributor Author

@qasimgulzar
Copy link
Contributor Author

@ormsbee I have created this repo to track tutor plugin development.

@qasimgulzar
Copy link
Contributor Author

Two PRs are left to be reviewed and merged.

@mphilbrick211
Copy link

@ormsbee friendly ping on this!

@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions Mar 3, 2025
@qasimgulzar
Copy link
Contributor Author

@ormsbee here I have created a tutor plugin to add postgresql in stack. for now It will run in parallel with mysql for development purpose but later I will set it to switch off the mysql.

@AntonOfTheWoods
Copy link

interesting what are you building? are you planning to replace tutor?

It's a k3d + Helm system that does basically everything important that tutor does, but without Docker Compose or Kustomize. I wanted postgres ready because I don't need or want to support MySQL or MongoDB. Mongo is replaced by ferretdb, which is postgres underneath.

I'll post to the forum when it's ready for comment. Hopefully in the next couple of days.

@AntonOfTheWoods
Copy link

@qasimgulzar , 61ac788 seems to work well. If you can cherry-pick or somehow update that, I'll submit the single change that needs to get submitted to the notes repo - the addition of this dep.

@AntonOfTheWoods
Copy link

@qasimgulzar , @ormsbee , if you guys are ok, would either of you mind if I help push this forward? I now have my build/deploy setup working how I need it, so am fully focussed on postgres support as the last blocker to get hacking on new features and helping out with some of the FE stuff.

If so, @ormsbee are there any extra things you'd like to see, like rebasing a straight set of commits on the tip of master rather than merges? How would be the best way to proceed? I create a new PR?

@qasimgulzar
Copy link
Contributor Author

@qasimgulzar , @ormsbee , if you guys are ok, would either of you mind if I help push this forward? I now have my build/deploy setup working how I need it, so am fully focussed on postgres support as the last blocker to get hacking on new features and helping out with some of the FE stuff.

If so, @ormsbee are there any extra things you'd like to see, like rebasing a straight set of commits on the tip of master rather than merges? How would be the best way to proceed? I create a new PR?

@AntonOfTheWoods once this PR will be merged we are expecting edx-platform repo to support postgresql. I will be focusing on other part of it once it's merged. Meanwhile let me know if I can be helpful for you.

@AntonOfTheWoods
Copy link

@AntonOfTheWoods once this PR will be merged we are expecting edx-platform repo to support postgresql. I will be focusing on other part of it once it's merged. Meanwhile let me know if I can be helpful for you.

@qasimgulzar thanks, I think I just need the remaining repos' support now. I just added the psycopg dep to openedx-learning and it installs, but further reading openedx/openedx-learning#255 suggests there is a little more work to do. In any case, my understanding of the above is that @ormsbee is still waiting on confirmation for the opaque keys question for this to get merged. As it looks like the work hasn't started on openedx-learning for the case insensitive collations, I guess that means support won't make it into ulma, so I'll need to build my own images till verawood anyway.

@qasimgulzar
Copy link
Contributor Author

qasimgulzar commented Oct 19, 2025

@AntonOfTheWoods i believe the PR for openedx-learning is already merged. Around that issue.

Oh may be you are right the case sensitive thing. Let me test that

@ormsbee
Copy link
Contributor

ormsbee commented Oct 20, 2025

For openedx-learning, case sensitive and case insensitive fields are usually generated from this helper module, which would probably be a good place to put in postgres-specific logic:

https://github.com/openedx/openedx-learning/blob/main/openedx_learning/lib/fields.py

You can see how it's done for MySQL and sqlite today:

@qasimgulzar
Copy link
Contributor Author

@ormsbee This PR is ready for another iteration, probably we can handle case insensitive index in separate PR as that is not a blocker for this PR to be merged. Please let me know if you need any other updates.
@AntonOfTheWoods I am sorry I was very busy last weeks with other client things. let me know if I can help you out in anyway.

@mphilbrick211
Copy link

@ormsbee This PR is ready for another iteration, probably we can handle case insensitive index in separate PR as that is not a blocker for this PR to be merged. Please let me know if you need any other updates. @AntonOfTheWoods I am sorry I was very busy last weeks with other client things. let me know if I can help you out in anyway.

Flagging this, @ormsbee @AntonOfTheWoods

@qasimgulzar
Copy link
Contributor Author

@ormsbee it's just a nudge

@mphilbrick211
Copy link

@ormsbee it's just a nudge

Same @ormsbee :)

@AntonOfTheWoods
Copy link

@mphilbrick211 , @ormsbee seems very busy. Maybe there is another maintainer who could take a look? The PR seems to have been opened over a year ago now and many other PG-related PRs seem to have already been merged.

@ormsbee
Copy link
Contributor

ormsbee commented Dec 15, 2025

Sorry folks, I'll do another pass by end of day Tuesday. Thank you.


def adapt_course_locator(course_locator):

return QuotedString(course_locator._to_string()) # lint-amnesty, pylint: disable=protected-access
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I mean why course_locator._to_string()? But if you're deleting it anyway, it's a moot point.

]

operations = [
migrations.CreateModel(
Copy link
Contributor

Choose a reason for hiding this comment

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

If openedx/openedx-learning#422 merges, would this be re-done in that style?

Choose a reason for hiding this comment

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

I can certainly take care of that if desired.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AntonOfTheWoods could you look into this point if you have sometime.

Choose a reason for hiding this comment

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

@qasimgulzar I certainly will but I'd very much like someone more familiar with the code to comment on that PR. One of the key points is that your current code is, unless I'm mistaken, pg14+ compatible.

Officially that draft PR of mine doesn't do everything that the mysql version does - notably, it simply throws away any indexes on case-insensitive columns. Postgresql Has CIText for that but it's been "deprecated" for many years and the field type has already been removed from Django core. As such, using that would require quite a bit of extra thought and work.

Adding index-supported case-insensitive columns for postgres would require significant extra work and testing for <pg18, and as I mentioned in the PR, I couldn't see anywhere it could make a difference. I'm an openedx n00b though. If we forget about supporting anything less than pg18, then I think we can add the indexes back. I looked at that almost 2 months ago now, so there may have been an extra reason for indexes not working exactly the same with pg18+.

The overwhelming majority of the changes on that PR are just making the code DRYer (using a pre-existing function that could have been used previously anyway), so there isn't actually that much to review - the main point is the "silent" removing of the index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ormsbee after giving a look to PR and above comment, We don't really need to re-do any thing in this context.


# primary key will need to be large for this table
id = UnsignedBigIntAutoField(primary_key=True) # pylint: disable=invalid-name
id = models.BigAutoField(primary_key=True) # pylint: disable=invalid-name
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, maybe I'm just being dense here, but won't this still be a problem if I have an existing site and want to later add a foreign key that references this model? Because my existing site will have this primary key in the database as type "unsigned bigint". But the code here says it's actually an "bigint" now. So then when I make a new model that has a foreign key to PersistentSubsectionGrade, won't the migration try to generate that foreign key as type "bigint"? Which will work fine on new installs, but blow up if I have an older site?

FYI: @feanil, @bmedx

Copy link
Contributor

@ormsbee ormsbee Dec 17, 2025

Choose a reason for hiding this comment

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

I know you went over this before in an earlier thread, but I think there's something I'm just not understanding properly.

Thank you for your patience.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ormsbee That seems correct to me, but I haven't tested this kind of thing in years.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ormsbee I have tested it with mysql and it is not treating it as type change, I also have updated the underlaying migrations to use this type so that it doesn't cause any discrepancy for new installs. for existing users these migrations also not going to trigger even so it seems safe.
If you have any particular scenario please let me know.

@AntonOfTheWoods
Copy link

@qasimgulzar , just a gentle nudge...

@qasimgulzar
Copy link
Contributor Author

I will look into it over the weekend.

@qasimgulzar qasimgulzar requested a review from ormsbee December 20, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: In Eng Review

Development

Successfully merging this pull request may close these issues.

8 participants