Skip to content

Commit

Permalink
change users table name
Browse files Browse the repository at this point in the history
  • Loading branch information
nayak-nirmalya committed Apr 20, 2024
1 parent c502f56 commit 7ed2510
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@types/react": "^18",
"@types/react-dom": "^18",
"dotenv": "^16.4.5",
"drizzle-kit": "^0.20.14",
"drizzle-kit": "^0.20.16",
"eslint": "^8",
"eslint-config-next": "14.2.2",
"pg": "^8.11.5",
Expand Down
45 changes: 32 additions & 13 deletions pnpm-lock.yaml

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

10 changes: 5 additions & 5 deletions src/app/api/webhooks/clerk/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { WebhookEvent } from "@clerk/nextjs/server";
import { eq } from "drizzle-orm";

import db from "@/db/drizzle";
import { users } from "@/db/schema";
import { user } from "@/db/schema";

export async function POST(req: Request) {
const WEBHOOK_SECRET = process.env.CLERK_WEBHOOK_SECRET;
Expand Down Expand Up @@ -54,7 +54,7 @@ export async function POST(req: Request) {
const eventType = evt.type;

if (eventType === "user.created") {
await db.insert(users).values({
await db.insert(user).values({
userId: payload.data.id,
username: payload.data.username,
firstName: payload.data.first_name,
Expand All @@ -65,18 +65,18 @@ export async function POST(req: Request) {

if (eventType === "user.updated") {
await db
.update(users)
.update(user)
.set({
username: payload.data.username,
firstName: payload.data.first_name,
lastName: payload.data.last_name,
email: payload.data.email_addresses[0].email_address,
})
.where(eq(users.userId, payload.data.id));
.where(eq(user.userId, payload.data.id));
}

if (eventType === "user.deleted") {
await db.delete(users).where(eq(users.userId, payload.data.id));
await db.delete(user).where(eq(user.userId, payload.data.id));
}

return new Response("", { status: 200 });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
CREATE TABLE IF NOT EXISTS "users" (
CREATE TABLE IF NOT EXISTS "user" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" varchar(255) NOT NULL,
"username" varchar(255) NOT NULL,
"first_name" varchar(255) NOT NULL,
"last_name" varchar(255) NOT NULL,
"email" text NOT NULL,
CONSTRAINT "users_username_unique" UNIQUE("username"),
CONSTRAINT "users_email_unique" UNIQUE("email")
CONSTRAINT "user_username_unique" UNIQUE("username"),
CONSTRAINT "user_email_unique" UNIQUE("email")
);
14 changes: 7 additions & 7 deletions src/db/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"id": "239212e0-bdde-4f14-9e93-5b47b3842659",
"id": "c4ae4a03-f33d-4e76-a766-3f5c4d548c37",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"tables": {
"users": {
"name": "users",
"user": {
"name": "user",
"schema": "",
"columns": {
"id": {
Expand Down Expand Up @@ -49,15 +49,15 @@
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {
"users_username_unique": {
"name": "users_username_unique",
"user_username_unique": {
"name": "user_username_unique",
"nullsNotDistinct": false,
"columns": [
"username"
]
},
"users_email_unique": {
"name": "users_email_unique",
"user_email_unique": {
"name": "user_email_unique",
"nullsNotDistinct": false,
"columns": [
"email"
Expand Down
4 changes: 2 additions & 2 deletions src/db/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
{
"idx": 0,
"version": "5",
"when": 1713540173236,
"tag": "0000_calm_blindfold",
"when": 1713598167983,
"tag": "0000_clammy_scarlet_spider",
"breakpoints": true
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/db/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { text, pgTable, serial, varchar } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
export const user = pgTable("user", {
id: serial("id").primaryKey(),
userId: varchar("user_id", { length: 255 }).notNull(),
username: varchar("username", { length: 255 }).notNull().unique(),
Expand Down

0 comments on commit 7ed2510

Please sign in to comment.