Skip to content

Commit

Permalink
bump drizzle (#1206)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Oct 7, 2024
1 parent 86c5f88 commit 99f1b4e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 72 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"engines": {
"node": ">=20.16.0"
},
"packageManager": "pnpm@9.7.1",
"packageManager": "pnpm@9.12.0",
"scripts": {
"build": "turbo run build",
"clean": "git clean -xdf node_modules",
Expand Down
1 change: 1 addition & 0 deletions packages/db/drizzle.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export default {
schema: "./src/schema.ts",
dialect: "postgresql",
dbCredentials: { url: nonPoolingUrl },
casing: "snake_case",
} satisfies Config;
4 changes: 2 additions & 2 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"dependencies": {
"@vercel/postgres": "^0.9.0",
"drizzle-orm": "^0.33.0",
"drizzle-orm": "^0.34.0",
"drizzle-zod": "^0.5.1",
"zod": "catalog:"
},
Expand All @@ -40,7 +40,7 @@
"@acme/prettier-config": "workspace:*",
"@acme/tsconfig": "workspace:*",
"dotenv-cli": "^7.4.2",
"drizzle-kit": "^0.24.2",
"drizzle-kit": "^0.25.0",
"eslint": "catalog:",
"prettier": "catalog:",
"typescript": "catalog:"
Expand Down
2 changes: 1 addition & 1 deletion packages/db/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import { drizzle } from "drizzle-orm/vercel-postgres";

import * as schema from "./schema";

export const db = drizzle(sql, { schema });
export const db = drizzle(sql, { schema, casing: "snake_case" });
88 changes: 38 additions & 50 deletions packages/db/src/schema.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import { relations, sql } from "drizzle-orm";
import {
integer,
pgTable,
primaryKey,
text,
timestamp,
uuid,
varchar,
} from "drizzle-orm/pg-core";
import { pgTable, primaryKey } from "drizzle-orm/pg-core";
import { createInsertSchema } from "drizzle-zod";
import { z } from "zod";

export const Post = pgTable("post", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
title: varchar("name", { length: 256 }).notNull(),
content: text("content").notNull(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updatedAt", {
mode: "date",
withTimezone: true,
}).$onUpdateFn(() => sql`now()`),
});
export const Post = pgTable("post", (t) => ({
id: t.uuid().notNull().primaryKey().defaultRandom(),
title: t.varchar({ length: 256 }).notNull(),
content: t.text().notNull(),
createdAt: t.timestamp().defaultNow().notNull(),
updatedAt: t
.timestamp({ mode: "date", withTimezone: true })
.$onUpdateFn(() => sql`now()`),
}));

export const CreatePostSchema = createInsertSchema(Post, {
title: z.string().max(256),
Expand All @@ -31,40 +22,39 @@ export const CreatePostSchema = createInsertSchema(Post, {
updatedAt: true,
});

export const User = pgTable("user", {
id: uuid("id").notNull().primaryKey().defaultRandom(),
name: varchar("name", { length: 255 }),
email: varchar("email", { length: 255 }).notNull(),
emailVerified: timestamp("emailVerified", {
mode: "date",
withTimezone: true,
}),
image: varchar("image", { length: 255 }),
});
export const User = pgTable("user", (t) => ({
id: t.uuid().notNull().primaryKey().defaultRandom(),
name: t.varchar({ length: 255 }),
email: t.varchar({ length: 255 }).notNull(),
emailVerified: t.timestamp({ mode: "date", withTimezone: true }),
image: t.varchar({ length: 255 }),
}));

export const UserRelations = relations(User, ({ many }) => ({
accounts: many(Account),
}));

export const Account = pgTable(
"account",
{
userId: uuid("userId")
(t) => ({
userId: t
.uuid()
.notNull()
.references(() => User.id, { onDelete: "cascade" }),
type: varchar("type", { length: 255 })
type: t
.varchar({ length: 255 })
.$type<"email" | "oauth" | "oidc" | "webauthn">()
.notNull(),
provider: varchar("provider", { length: 255 }).notNull(),
providerAccountId: varchar("providerAccountId", { length: 255 }).notNull(),
refresh_token: varchar("refresh_token", { length: 255 }),
access_token: text("access_token"),
expires_at: integer("expires_at"),
token_type: varchar("token_type", { length: 255 }),
scope: varchar("scope", { length: 255 }),
id_token: text("id_token"),
session_state: varchar("session_state", { length: 255 }),
},
provider: t.varchar({ length: 255 }).notNull(),
providerAccountId: t.varchar({ length: 255 }).notNull(),
refresh_token: t.varchar({ length: 255 }),
access_token: t.text(),
expires_at: t.integer(),
token_type: t.varchar({ length: 255 }),
scope: t.varchar({ length: 255 }),
id_token: t.text(),
session_state: t.varchar({ length: 255 }),
}),
(account) => ({
compoundKey: primaryKey({
columns: [account.provider, account.providerAccountId],
Expand All @@ -76,16 +66,14 @@ export const AccountRelations = relations(Account, ({ one }) => ({
user: one(User, { fields: [Account.userId], references: [User.id] }),
}));

export const Session = pgTable("session", {
sessionToken: varchar("sessionToken", { length: 255 }).notNull().primaryKey(),
userId: uuid("userId")
export const Session = pgTable("session", (t) => ({
sessionToken: t.varchar({ length: 255 }).notNull().primaryKey(),
userId: t
.uuid()
.notNull()
.references(() => User.id, { onDelete: "cascade" }),
expires: timestamp("expires", {
mode: "date",
withTimezone: true,
}).notNull(),
});
expires: t.timestamp({ mode: "date", withTimezone: true }).notNull(),
}));

export const SessionRelations = relations(Session, ({ one }) => ({
user: one(User, { fields: [Session.userId], references: [User.id] }),
Expand Down
38 changes: 20 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 99f1b4e

Please sign in to comment.