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: sqlite enums #5101

Merged
merged 12 commits into from
Jan 6, 2025
Merged

feat: sqlite enums #5101

merged 12 commits into from
Jan 6, 2025

Conversation

jacek-prisma
Copy link
Contributor

@jacek-prisma jacek-prisma commented Dec 31, 2024

ORM-479
Relates to prisma/prisma#2219.

Implements enums in sqlite in a way similar to Mongo, the conversions are handled in the query engine, while the migrations treats them as strings (you can transition from and to enums without migration steps).

Notes

  • We currently warn about breaking changes to enum schema for MySQL and PSQL, there is no such warning for SQLite, because these warnings are generated based on introspection, which we can't do in the same way for enums in SQLite (it's possible to have a similar warning but it'd need to be implemented differently, I opted not to do it to avoid additional complexity).

  • If the user ends up with an unknown enum in the database the queries will fail (analogous to Mongo):

    SQLite behavior
    Invalid `prisma.user.findMany()` invocation in
    /Users/jacek/code/prisma/sandbox/basic-sqlite/index.ts:8:35
    
      5
      6 await prisma.$executeRaw`INSERT INTO "User" ("id", "plan") VALUES ('2', 'NONFREE')`
      7
    → 8 const users = await prisma.user.findMany(
    Value 'NONFREE' not found in enum 'Plan'
    
    Mongo behavior
    Invalid `prisma.user.findMany()` invocation in
    /Users/jacek/code/prisma/sandbox/basic-mongo/index.ts:14:35
    
      11   }]
      12 })
      13
    → 14 const users = await prisma.user.findMany(
    Value 'NONFREE' not found in enum 'Plan'
    

Copy link

codspeed-hq bot commented Dec 31, 2024

CodSpeed Performance Report

Merging #5101 will not alter performance

Comparing feat/sqlite-enum (f78d16b) with main (c49e56c)

Summary

✅ 11 untouched benchmarks

Copy link
Contributor

github-actions bot commented Dec 31, 2024

WASM Query Engine file Size

Engine This PR Base branch Diff
Postgres 2.095MiB 2.095MiB 0.000B
Postgres (gzip) 840.894KiB 840.894KiB 0.000B
Mysql 2.056MiB 2.056MiB 0.000B
Mysql (gzip) 827.512KiB 827.513KiB -1.000B
Sqlite 1.971MiB 1.971MiB 0.000B
Sqlite (gzip) 792.149KiB 792.150KiB -1.000B

@jacek-prisma jacek-prisma added this to the 6.2.0 milestone Jan 2, 2025
@jacek-prisma jacek-prisma marked this pull request as ready for review January 2, 2025 12:02
@jacek-prisma jacek-prisma requested a review from a team as a code owner January 2, 2025 12:02
@jacek-prisma jacek-prisma requested review from aqrln and removed request for a team January 2, 2025 12:02
Comment on lines 84 to 89

(
Some(DefaultKind::Value(PrismaValue::Enum(prev) | PrismaValue::String(prev))),
Some(DefaultKind::Value(PrismaValue::String(next) | PrismaValue::Enum(next))),
) => prev == next && names_match,

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add a bit more context here, @jacek-prisma? Thanks.

E.g., if we change an enum to a string, do we generate a migration for it? E.g., in Postgres we want a migration.sql file, in SQLite, we don't.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jkomyno this is for default values specifically, the reason I need to add this is that the default value derived from introspection is a String while the Prisma-level default value is derived to be an Enum, I had to modify this comparison to have that produce no diff

Copy link
Contributor Author

@jacek-prisma jacek-prisma Jan 6, 2025

Choose a reason for hiding this comment

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

added a comment

@jkomyno jkomyno merged commit 51db5cf into main Jan 6, 2025
367 checks passed
@jkomyno jkomyno deleted the feat/sqlite-enum branch January 6, 2025 16:14
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