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

feat: upgrading django-oauth-toolkit==1.5.0 #33079

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

awais786
Copy link
Contributor

@awais786 awais786 commented Aug 23, 2023

https://github.com/jazzband/django-oauth-toolkit/blob/master/CHANGELOG.md#150-2021-03-18

https://github.com/jazzband/django-oauth-toolkit/blob/1.5.0/oauth2_provider/migrations/0004_auto_20200902_2022.py

models.py this file contains the model related changes.

RAW SQL

-- Add field algorithm to application
--
ALTER TABLE `oauth2_provider_application` ADD COLUMN `algorithm` varchar(5) DEFAULT '' NOT NULL;
ALTER TABLE `oauth2_provider_application` ALTER COLUMN `algorithm` DROP DEFAULT;
--
-- Alter field authorization_grant_type on application
--
--
-- Create model IDToken
--
CREATE TABLE `oauth2_provider_idtoken` (`id` bigint AUTO_INCREMENT NOT NULL PRIMARY KEY, `jti` char(32) NOT NULL UNIQUE, `expires` datetime(6) NOT NULL, `scope` longtext NOT NULL, `created` datetime(6) NOT NULL, `updated` datetime(6) NOT NULL, `application_id` bigint NULL, `user_id` integer NULL);
--
-- Add field id_token to accesstoken
--
ALTER TABLE `oauth2_provider_accesstoken` ADD COLUMN `id_token_id` bigint NULL UNIQUE , ADD CONSTRAINT `oauth2_provider_acce_id_token_id_85db651b_fk_oauth2_pr` FOREIGN KEY (`id_token_id`) REFERENCES `oauth2_provider_idtoken`(`id`);
--
-- Add field nonce to grant
--
ALTER TABLE `oauth2_provider_grant` ADD COLUMN `nonce` varchar(255) DEFAULT '' NOT NULL;
ALTER TABLE `oauth2_provider_grant` ALTER COLUMN `nonce` DROP DEFAULT;
--
-- Add field claims to grant
--
ALTER TABLE `oauth2_provider_grant` ADD COLUMN `claims` longtext DEFAULT ('') NOT NULL;
ALTER TABLE `oauth2_provider_idtoken` ADD CONSTRAINT `oauth2_provider_idto_application_id_08c5ff4f_fk_oauth2_pr` FOREIGN KEY (`application_id`) REFERENCES `oauth2_provider_application` (`id`);
ALTER TABLE `oauth2_provider_idtoken` ADD CONSTRAINT `oauth2_provider_idtoken_user_id_dd512b59_fk_auth_user_id` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`);

@awais786
Copy link
Contributor Author

select count(*) from oauth2_provider_application;
+----------+
| count(*) |
+----------+
|      740 |
+----------+
1 row in set (0.00 sec)

@awais786
Copy link
Contributor Author

awais786 commented Aug 23, 2023

mysql> select count(*) from oauth2_provider_accesstoken;
+----------+
| count(*) |
+----------+
| 20552959 |
+----------+
1 row in set (19.20 sec)

twenty million five hundred fifty-two thousand nine hundred fifty-nine

@awais786
Copy link
Contributor Author

select count(*) from oauth2_provider_grant;
+----------+
| count(*) |
+----------+
|    25264 |
+----------+
1 row in set (0.10 sec)

@awais786 awais786 changed the title feat: upgrading django-oauth-toolkit feat: upgrading django-oauth-toolkit==1.5.0 Aug 23, 2023
@awais786
Copy link
Contributor Author

mysql> select count(*) from oauth2_provider_accesstoken;
+----------+
| count(*) |
+----------+
| 20552959 |
+----------+
1 row in set (19.20 sec)

twenty million five hundred fifty-two thousand nine hundred fifty-nine

@robrap need your guidance in this migration. Thanks

@awais786
Copy link
Contributor Author

awais786 commented Aug 23, 2023

NOTE: check prod/stage for this upgrde, table size is huge.

@robrap
Copy link
Contributor

robrap commented Aug 23, 2023

Hello @awais786. @rgraber is both on-call and our eSRE. I know of these issues in general, but typically I'd go to SRE. Maybe @rgraber can either support you or help work with SRE on this to learn best practices.

@awais786
Copy link
Contributor Author

@rgraber may be it can be run on clone first and see if there is any issue ?

@rgraber
Copy link
Contributor

rgraber commented Aug 25, 2023

@rgraber may be it can be run on clone first and see if there is any issue ?

I think I can do this. I'm consulting with SRE now.

@rgraber
Copy link
Contributor

rgraber commented Aug 25, 2023

From Nadeem:

The only concerned query is where we are adding nullable Columba for a large table which contain 20 million rows
ALTER TABLE oauth2_provider_accesstoken ADD COLUMN id_token_id bigint NULL UNIQUE ,
Specifically, the statement in the AWS documentation mentions that Fast DDL only supports adding nullable columns to the end of an existing table. Our query is adding a nullable column (id_token_id) to the existing table oauth2_provider_accesstoken, which aligns with this statement.
However, it is also specifying UNIQUE on the new column. We are using feature Fast DDL but the addition of the UNIQUE constraint might still can take time on large table.

@mumarkhan999 mumarkhan999 force-pushed the upgrade-django-oauth-toolkit branch from cd052a0 to 098d59e Compare September 15, 2023 09:44
@mumarkhan999 mumarkhan999 marked this pull request as ready for review September 15, 2023 09:45
@mumarkhan999 mumarkhan999 self-assigned this Sep 15, 2023
@mumarkhan999 mumarkhan999 merged commit 55260b9 into master Sep 18, 2023
@mumarkhan999 mumarkhan999 deleted the upgrade-django-oauth-toolkit branch September 18, 2023 09:40
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

1 similar comment
@edx-pipeline-bot
Copy link
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants