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 missing indices to resolve #1067 #1069

Merged
merged 3 commits into from
Oct 6, 2018

Conversation

aaslamin
Copy link
Contributor

@aaslamin aaslamin commented Oct 3, 2018

Resolves #1067 by adding indices to:

request_id column in the hydra_oauth2_access & hydra_oauth2_refresh tables
requested_at column in the hydra_oauth2_access table

Review: @aeneasr

@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 3, 2018

I wasn't sure if you had a naming convention for indices. Please let me know if you would like me to update the names.

To test the migrations, I applied them on both postgres and mysql using the supplied docker-compose setup.

@@ -87,6 +87,8 @@ func sqlSchemaUp(table string, id string) string {
subject varchar(255) NOT NULL
)`,
"4": fmt.Sprintf("ALTER TABLE hydra_oauth2_%s ADD active BOOL NOT NULL DEFAULT TRUE", table),
"5": fmt.Sprintf("CREATE INDEX hydra_oauth2_%s_request_id_idx ON hydra_oauth2_%s (request_id)", table, table),
Copy link
Member

Choose a reason for hiding this comment

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

I think it would make sense to have an unique index. They key should really be unique and it will help with query speed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch 👍

Copy link
Member

Choose a reason for hiding this comment

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

lmao 2 years later and I found that this new unique index actually breaks OpenID Connect compliance...welp 🤷

},
},
{
Id: "6",
Copy link
Member

Choose a reason for hiding this comment

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

These two can be merged, no?

Copy link
Contributor Author

@aaslamin aaslamin Oct 5, 2018

Choose a reason for hiding this comment

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

@aeneasr I had to keep them separate because I only wanted to create an index on the requested_at column on the hydra_oauth2_access table.

I guess I could add a semicolon and add another statement to migration 5?

Copy link
Member

Choose a reason for hiding this comment

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

Oh yeah, I see, this is because of the function design. Let's keep it the way you have it

@aeneasr
Copy link
Member

aeneasr commented Oct 5, 2018

Please also add a test. Since you didn't change the schema it's probably enough to re-enter the previous data again but with a new ID.

@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 5, 2018

@aeneasr maybe I am being stupid 😅, but I am not sure how adding the test to https://github.com/ory/hydra/blob/master/client/manager_0_sql_migrations_test.go will work? That test seems to be specifically around migrations related to the client manager?

@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 5, 2018

Thanks for the feedback! Will address in the morning 🙌

@aaslamin aaslamin force-pushed the 1067-add-missing-indices branch from f9cb97a to 2718474 Compare October 5, 2018 18:53
• `request_id` column in the hydra_oauth2_access & hydra_oauth2_refresh tables
• `requested_at` column in the hydra_oauth2_access table

Signed-off-by: Amir Aslaminejad <[email protected]>
@aaslamin aaslamin force-pushed the 1067-add-missing-indices branch from 2718474 to 7ff3e53 Compare October 5, 2018 19:33
@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 5, 2018

Update:

• Changed index to a unique index on the request_id column
• Investigating failing tests as a result of that change now

… on the request_id column

Signed-off-by: Amir Aslaminejad <[email protected]>
@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 5, 2018

Update

• Fixed broken test - there was a test that was inserting multiple records with the same request_id. The system works 😎

@aeneasr
Copy link
Member

aeneasr commented Oct 5, 2018

Nice! I'll review that tomorrow!

…the `request_id` column in the hydra_oauth2_access and hydra_oauth2_refresh tables.

Signed-off-by: Amir Aslaminejad <[email protected]>
@aaslamin aaslamin force-pushed the 1067-add-missing-indices branch from d505fc2 to 2399d83 Compare October 5, 2018 22:28
@aaslamin
Copy link
Contributor Author

aaslamin commented Oct 5, 2018

Update:

• Added new test coverage to cover the unique constraints placed on the request_id column in the hydra_oauth2_access & hydra_oauth2_refresh tables.

This PR is ready for potentially a final review @aeneasr 🤝

@aeneasr
Copy link
Member

aeneasr commented Oct 6, 2018

Thank you!

@aeneasr aeneasr merged commit 4401dd9 into ory:master Oct 6, 2018
@aaslamin aaslamin deleted the 1067-add-missing-indices branch October 6, 2018 06:29
aaslamin added a commit to aaslamin/hydra that referenced this pull request Oct 9, 2018
aaslamin added a commit to aaslamin/hydra that referenced this pull request Oct 9, 2018
aeneasr pushed a commit that referenced this pull request Oct 9, 2018
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.

2 participants