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

Migrating date times in sqlite generated by Prisma #1618

Closed
hoelter opened this issue Oct 25, 2024 · 0 comments
Closed

Migrating date times in sqlite generated by Prisma #1618

hoelter opened this issue Oct 25, 2024 · 0 comments

Comments

@hoelter
Copy link

hoelter commented Oct 25, 2024

I recently migrated a sqlite database created with prisma to postgres and ran into an issue that I ended up resolving, and want to leave a comment on this for anyone else who may end up running into the same issue I did.

In my prisma schema I had some DateTime values defined like createdAt DateTime @default(now()). This creates a sqlite column of sqlite type "DateTime" with the default CURRENT_TIMESTAMP. When running pgloader, the default casting types for sqlite don't handle this appropriately. It turns out this value was being saved as a unix time value with millisecond precision, so it needed a custom cast to succeed. My solution does not preserve the millisecond precision, but this may be good enough for others who don't need that level of accuracy for their use case.

Drop the "with quote identifiers" if you do not want to preserve casing. For that option to work properly, the fix in this PR was also required.

load database
    from sqlite:///<filepath>
    into pgsql://<connectionstring>

with quote identifiers

cast type datetime to timestamptz using (lambda (x) (unix-timestamp-to-timestamptz (if x (floor x 1000))))

excluding table names like '_prisma_migrations';

@hoelter hoelter closed this as completed Oct 25, 2024
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

No branches or pull requests

1 participant