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

Postgres Citext Support #4021

Merged
merged 2 commits into from
May 16, 2024
Merged

Conversation

tommymcc
Copy link
Contributor

Adds support for the Postgres citext type.

@tommymcc
Copy link
Contributor Author

Apologies, I'd created this PR against the Diesel repository rather than my own fork by accident. I had meant to ask in Gitter whether it would be acceptable first.

@tommymcc tommymcc changed the title Postgres CIText Support Postgres Citext Support May 11, 2024
@weiznich weiznich requested a review from a team May 13, 2024 08:42
let rows_inserted = insert_into(case_insensitive::table)
.values((
case_insensitive::non_null_ci.eq("UPPERCASE_VALUE".to_string()),
case_insensitive::nullable_ci.eq("lowercase_value".to_string()),
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we can put not a string but an &str on this one so that both types are tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds like a good call 👍

#[cfg(feature = "postgres_backend")]
#[derive(Debug, Clone, Copy, Default, QueryId, SqlType)]
#[diesel(postgres_type(name = "citext"))]
pub struct Citext;
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 we need to add this type to the list of types that are known by diesel in the cli when generating the schema, so that the cli doesn't generate the corresponding type in the schema.rs.

Im surprised you haven't encountered issues due to this during tests.
Did you run tests using the cli yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll have a look into that. I started working backwards using a schema generated without Citext support, I still have to test starting with schema generation. I'll check that and add get back to you with the results.

As I mentioned in Gitter, I'd jumped the gun a little on creating the PR before I had a chance to test properly but I'll make sure it all works before pushing any more changes.

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, I've updated the list of known types to include Citext and added a test to validate it generates the correct schema. Let me know if there's a better place I could put it.

I've also tested with our application in work and the test suite (which include case insensitively fetching a record by a citext field) passes.

Are there any other areas I need to consider?

@tommymcc tommymcc force-pushed the feature/citext-support branch from 2350f87 to 423847b Compare May 14, 2024 17:34
@weiznich weiznich added this pull request to the merge queue May 16, 2024
Merged via the queue into diesel-rs:master with commit 16c4cf7 May 16, 2024
48 checks passed
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.

3 participants