From 21af68b28a6bdac06da9520b6eeae29a9637e9eb Mon Sep 17 00:00:00 2001 From: juliusmarminge Date: Mon, 11 Sep 2023 22:56:56 +0200 Subject: [PATCH] drizzle-trpc: post import --- .../src/server/api/routers/post/with-auth-drizzle.ts | 1 + .../extras/src/server/db/drizzle-schema-auth.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts b/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts index 4dacb7a4a9..60448ff2df 100644 --- a/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts +++ b/cli/template/extras/src/server/api/routers/post/with-auth-drizzle.ts @@ -5,6 +5,7 @@ import { protectedProcedure, publicProcedure, } from "~/server/api/trpc"; +import { posts } from "~/server/db/schema"; export const createPost = publicProcedure .input(z.object({ text: z.string().min(1) })) diff --git a/cli/template/extras/src/server/db/drizzle-schema-auth.ts b/cli/template/extras/src/server/db/drizzle-schema-auth.ts index ee154f7e78..9e9f023ea3 100644 --- a/cli/template/extras/src/server/db/drizzle-schema-auth.ts +++ b/cli/template/extras/src/server/db/drizzle-schema-auth.ts @@ -20,18 +20,20 @@ import { type AdapterAccount } from "next-auth/adapters"; */ export const mysqlTable = mysqlTableCreator((name) => `project1_${name}`); -export const example = mysqlTable( - "example", +export const posts = mysqlTable( + "post", { id: bigint("id", { mode: "number" }).primaryKey().autoincrement(), - name: varchar("name", { length: 256 }), + text: varchar("name", { length: 256 }), + createdById: varchar("createdById", { length: 255 }).notNull(), createdAt: timestamp("created_at") .default(sql`CURRENT_TIMESTAMP`) .notNull(), updatedAt: timestamp("updatedAt").onUpdateNow(), }, (example) => ({ - nameIndex: uniqueIndex("name_idx").on(example.name), + createdByIdIdx: index("createdById_idx").on(example.createdById), + textIndex: uniqueIndex("text_idx").on(example.text), }) );