-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f37eae3
commit 00219bc
Showing
11 changed files
with
501 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
CREATE TABLE IF NOT EXISTS "auth"."users" ( | ||
"id" uuid PRIMARY KEY NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "wc_profile" ( | ||
"id" uuid PRIMARY KEY NOT NULL, | ||
"name" varchar(256) NOT NULL, | ||
"image" varchar(256), | ||
"email" varchar(256) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "wc_report" ( | ||
"id" serial PRIMARY KEY NOT NULL, | ||
"title" varchar(256) NOT NULL, | ||
"content" text NOT NULL, | ||
"profile_id" uuid NOT NULL, | ||
"created_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL, | ||
"updated_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL | ||
); | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "wc_profile" ADD CONSTRAINT "wc_profile_id_users_id_fk" FOREIGN KEY ("id") REFERENCES "auth"."users"("id") ON DELETE cascade ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "wc_report" ADD CONSTRAINT "wc_report_profile_id_wc_profile_id_fk" FOREIGN KEY ("profile_id") REFERENCES "wc_profile"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"id": "225a9ba0-acad-4d5c-ac65-73a6d7d8af6a", | ||
"prevId": "00000000-0000-0000-0000-000000000000", | ||
"version": "5", | ||
"dialect": "pg", | ||
"tables": { | ||
"users": { | ||
"name": "users", | ||
"schema": "auth", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "uuid", | ||
"primaryKey": true, | ||
"notNull": true | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"wc_profile": { | ||
"name": "wc_profile", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "uuid", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"image": { | ||
"name": "image", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"email": { | ||
"name": "email", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": { | ||
"wc_profile_id_users_id_fk": { | ||
"name": "wc_profile_id_users_id_fk", | ||
"tableFrom": "wc_profile", | ||
"tableTo": "users", | ||
"schemaTo": "auth", | ||
"columnsFrom": [ | ||
"id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "cascade", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"wc_report": { | ||
"name": "wc_report", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "serial", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"title": { | ||
"name": "title", | ||
"type": "varchar(256)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"content": { | ||
"name": "content", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"profile_id": { | ||
"name": "profile_id", | ||
"type": "uuid", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "CURRENT_TIMESTAMP" | ||
}, | ||
"updated_at": { | ||
"name": "updated_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "CURRENT_TIMESTAMP" | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": { | ||
"wc_report_profile_id_wc_profile_id_fk": { | ||
"name": "wc_report_profile_id_wc_profile_id_fk", | ||
"tableFrom": "wc_report", | ||
"tableTo": "wc_profile", | ||
"columnsFrom": [ | ||
"profile_id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "no action", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
} | ||
}, | ||
"enums": {}, | ||
"schemas": {}, | ||
"_meta": { | ||
"columns": {}, | ||
"schemas": {}, | ||
"tables": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": "5", | ||
"dialect": "pg", | ||
"entries": [ | ||
{ | ||
"idx": 0, | ||
"version": "5", | ||
"when": 1715131176564, | ||
"tag": "0000_brainy_lila_cheney", | ||
"breakpoints": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { customAlphabet } from "nanoid"; | ||
|
||
export const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789"); | ||
|
||
export const timestamps: { createdAt: true; updatedAt: true } = { | ||
createdAt: true, | ||
updatedAt: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "./profile"; | ||
export * from "./post"; | ||
export * from "./report"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
import { relations } from "drizzle-orm"; | ||
import { varchar } from "drizzle-orm/pg-core"; | ||
import { uuid, varchar } from "drizzle-orm/pg-core"; | ||
|
||
import { createTable } from "./_table"; | ||
import { post } from "./post"; | ||
import { users } from "./auth"; | ||
import { report } from "./report"; | ||
|
||
export const profile = createTable("profile", { | ||
id: varchar("id", { length: 256 }).primaryKey(), | ||
// Matches id from auth.users table in Supabase | ||
id: uuid("id") | ||
.primaryKey() | ||
.references(() => users.id, { onDelete: "cascade" }), | ||
name: varchar("name", { length: 256 }).notNull(), | ||
image: varchar("image", { length: 256 }), | ||
email: varchar("email", { length: 256 }), | ||
}); | ||
|
||
export const profileRelations = relations(profile, ({ many }) => ({ | ||
posts: many(post), | ||
reports: many(report), | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { relations, sql } from "drizzle-orm"; | ||
import { serial, text, timestamp, uuid, varchar } from "drizzle-orm/pg-core"; | ||
import { createInsertSchema } from "drizzle-zod"; | ||
import { z } from "zod"; | ||
|
||
import { timestamps } from "../lib/utils"; | ||
import { createTable } from "./_table"; | ||
import { profile } from "./profile"; | ||
|
||
export const report = createTable("report", { | ||
id: serial("id").primaryKey(), | ||
title: varchar("title", { length: 256 }).notNull(), | ||
content: text("content").notNull(), | ||
profileId: uuid("profile_id") | ||
.notNull() | ||
.references(() => profile.id), | ||
createdAt: timestamp("created_at") | ||
.notNull() | ||
.default(sql`CURRENT_TIMESTAMP`), | ||
updatedAt: timestamp("updated_at") | ||
.notNull() | ||
.default(sql`CURRENT_TIMESTAMP`), | ||
}); | ||
|
||
export const reportRelations = relations(report, ({ one }) => ({ | ||
profile: one(profile, { | ||
fields: [report.profileId], | ||
references: [profile.id], | ||
}), | ||
})); | ||
|
||
export const createReportSchema = createInsertSchema(report).omit({ | ||
id: true, | ||
...timestamps, | ||
}); | ||
export type CreateReportInput = z.infer<typeof createReportSchema>; |
Oops, something went wrong.