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(drizzle): Migrate to Drizzle ORM #404

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

realmikesolo
Copy link

This PR was made to migrate from Prisma to Drizzle ORM. It involves rewriting the database interactions using Drizzle ORM.

Copy link

vercel bot commented May 8, 2024

@realmikesolo is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@leerob leerob left a comment

Choose a reason for hiding this comment

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

This is looking great!

@@ -113,7 +109,7 @@ export default async function SitePostPage({
href={
data.site?.user?.username
? `https://twitter.com/${data.site.user.username}`
: `https://github.com/${data.site?.user?.gh_username}`
: `https://github.com/${data.site?.user?.ghUsername}`
Copy link
Member

Choose a reason for hiding this comment

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

Would this require a data migration?

lib/actions.ts Outdated
})
.returning();

// unnecessary await
Copy link
Member

Choose a reason for hiding this comment

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

Remove the await?

lib/actions.ts Outdated
.where(eq(sites.id, site.id))
.returning();

await revalidateTag(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await revalidateTag(
revalidateTag(

lib/actions.ts Outdated
`${site.subdomain}.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}-metadata`,
);
response.customDomain &&
(await revalidateTag(`${site.customDomain}-metadata`));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(await revalidateTag(`${site.customDomain}-metadata`));
revalidateTag(`${site.customDomain}-metadata`);

lib/actions.ts Outdated
})
.returning();

await revalidateTag(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
await revalidateTag(
revalidateTag(

@m-torin
Copy link

m-torin commented May 9, 2024

It's an interesting choice to move away from a project that enterprises and governments support to one that's unknown and may require security reviews. What benefits make this worth it?

@leerob
Copy link
Member

leerob commented May 9, 2024

@m-torin if you would like to use Prisma, that's great. Please do! I don't have anything against Prisma. In fact, we just worked with them on this https://db-latency.vercel.app/.

@realmikesolo
Copy link
Author

realmikesolo commented May 11, 2024

I made some edits based on the review, updated the Drizzle schema, upgraded drizzle-kit to version 0.21.1, and created a new Prisma compatible schema with an initial migration. These can be used if switching from Prisma to Drizzle ORM. The migration was created after pulling the DDL from an existing database, which was initially used with Prisma. The only thing that needs to be done is to set the email field in the User table to 'not null' for type compatibility with the Drizzle adapter for next-auth.

Currently, there are two bugs related to drizzle-kit removing foreign key constraints and recreating them, and drizzle-kit detecting changes in timestamp precision even when there are none. These should be fixed soon. Once they are resolved, the Prisma compatible schema can be used. If it's a new project, it's recommended to use the standard Drizzle schema.

Please let me know if anything needs updating.

import { getPostData, getSiteData } from "@/lib/fetchers";
import BlogCard from "@/components/blog-card";
import BlurImage from "@/components/blur-image";
import MDX from "@/components/mdx";
import { placeholderBlurhash, toDateString } from "@/lib/utils";
import db from "@/lib/db/db";

Choose a reason for hiding this comment

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

inline


return posts.length > 0 ? (
const query = db

Choose a reason for hiding this comment

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

make in query syntax

});
const query = db
.select({
...getTableColumns(sites),

Choose a reason for hiding this comment

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

redundant

@realmikesolo
Copy link
Author

Bugs with Drizzle-kit were fixed

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.

None yet

4 participants