Skip to content

Commit

Permalink
drop unique constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge committed Sep 13, 2023
1 parent d027ac6 commit a97cfe9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 2 additions & 0 deletions cli/template/extras/prisma/schema/with-auth.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ model Post {
createdBy User @relation(fields: [createdById], references: [id])
createdById String
@@index([text])
}

// Necessary for Next auth
Expand Down
8 changes: 5 additions & 3 deletions cli/template/extras/src/app/_components/create-post.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
"use client";

import { useRouter } from "next/navigation";
import { useState } from "react";

import { api } from "~/trpc/react";

export function CreatePost() {
const router = useRouter();
const [text, setText] = useState("");

const createPost = api.post.create.useMutation({
onSuccess: () => {
router.refresh();
setText("");
},
});

return (
<form
onSubmit={(e) => {
e.preventDefault();

const text = new FormData(e.currentTarget).get("text") as string;
createPost.mutate({ text });
}}
className="flex flex-col gap-2"
>
<input
type="text"
name="text"
placeholder="Title"
value={text}
onChange={(e) => setText(e.target.value)}
className="w-full rounded-full px-4 py-2 text-black"
/>
<button
Expand Down
3 changes: 1 addition & 2 deletions cli/template/extras/src/server/db/drizzle-schema-auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
primaryKey,
text,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/mysql-core";
import { type AdapterAccount } from "next-auth/adapters";
Expand All @@ -33,7 +32,7 @@ export const posts = mysqlTable(
},
(example) => ({
createdByIdIdx: index("createdById_idx").on(example.createdById),
textIndex: uniqueIndex("text_idx").on(example.text),
textIndex: index("text_idx").on(example.text),
})
);

Expand Down
3 changes: 1 addition & 2 deletions cli/template/extras/src/server/db/drizzle-schema-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
bigint,
mysqlTableCreator,
timestamp,
uniqueIndex,
varchar,
} from "drizzle-orm/mysql-core";

Expand All @@ -29,6 +28,6 @@ export const posts = mysqlTable(
updatedAt: timestamp("updatedAt").onUpdateNow(),
},
(example) => ({
textIndex: uniqueIndex("text_idx").on(example.text),
textIndex: index("text_idx").on(example.text),
})
);

0 comments on commit a97cfe9

Please sign in to comment.