-
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.
Merge pull request #10 from Manudasari265/feat/express-server
feat:(db)/added projects schema
- Loading branch information
Showing
12 changed files
with
589 additions
and
6 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
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,5 @@ | ||
declare namespace Express { | ||
interface Request { | ||
userId?: string; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/db/drizzle/migrations/0002_curvy_blazing_skull.sql
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,20 @@ | ||
CREATE TABLE "projects" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"project_name" varchar(255) NOT NULL, | ||
"url" varchar NOT NULL, | ||
"private" boolean NOT NULL, | ||
"user_id" integer | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE "users" ( | ||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
"username" varchar(255) NOT NULL, | ||
"email" varchar(255) NOT NULL, | ||
"password" text NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"updated_at" timestamp DEFAULT now() NOT NULL, | ||
CONSTRAINT "users_username_unique" UNIQUE("username"), | ||
CONSTRAINT "users_email_unique" UNIQUE("email") | ||
); | ||
--> statement-breakpoint | ||
DROP TABLE "user" CASCADE; |
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,130 @@ | ||
{ | ||
"id": "fb307380-5200-441c-bc8c-ad262458853d", | ||
"prevId": "58eb7d31-18ee-4256-b85a-6ff80d9a69ea", | ||
"version": "7", | ||
"dialect": "postgresql", | ||
"tables": { | ||
"public.projects": { | ||
"name": "projects", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "uuid", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"default": "gen_random_uuid()" | ||
}, | ||
"project_name": { | ||
"name": "project_name", | ||
"type": "varchar(255)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"url": { | ||
"name": "url", | ||
"type": "varchar", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"private": { | ||
"name": "private", | ||
"type": "boolean", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"user_id": { | ||
"name": "user_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {}, | ||
"policies": {}, | ||
"checkConstraints": {}, | ||
"isRLSEnabled": false | ||
}, | ||
"public.users": { | ||
"name": "users", | ||
"schema": "", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "uuid", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"default": "gen_random_uuid()" | ||
}, | ||
"username": { | ||
"name": "username", | ||
"type": "varchar(255)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"email": { | ||
"name": "email", | ||
"type": "varchar(255)", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"password": { | ||
"name": "password", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "now()" | ||
}, | ||
"updated_at": { | ||
"name": "updated_at", | ||
"type": "timestamp", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"default": "now()" | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": { | ||
"users_username_unique": { | ||
"name": "users_username_unique", | ||
"nullsNotDistinct": false, | ||
"columns": [ | ||
"username" | ||
] | ||
}, | ||
"users_email_unique": { | ||
"name": "users_email_unique", | ||
"nullsNotDistinct": false, | ||
"columns": [ | ||
"email" | ||
] | ||
} | ||
}, | ||
"policies": {}, | ||
"checkConstraints": {}, | ||
"isRLSEnabled": false | ||
} | ||
}, | ||
"enums": {}, | ||
"schemas": {}, | ||
"sequences": {}, | ||
"roles": {}, | ||
"policies": {}, | ||
"views": {}, | ||
"_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
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,17 +1,39 @@ | ||
import { relations } from "drizzle-orm"; | ||
import { | ||
pgTable, | ||
text, | ||
uuid, | ||
varchar, | ||
timestamp | ||
timestamp, | ||
boolean, | ||
integer | ||
} from "drizzle-orm/pg-core"; | ||
|
||
|
||
export const user = pgTable('user', { | ||
export const users = pgTable('users', { | ||
id: uuid("id").primaryKey().defaultRandom(), | ||
username: varchar("username", { length: 255 }).unique().notNull(), | ||
email: varchar("email", { length: 255 }).unique().notNull(), | ||
password: text("password").notNull(), | ||
createdAt: timestamp("created_at", { mode: "string" }).notNull().defaultNow(), | ||
updatedAt: timestamp("updated_at", { mode: "string" }).notNull().defaultNow(), | ||
}) | ||
}); | ||
|
||
export const userRelations = relations(users, ({ many }) => ({ | ||
projects: many(projects), | ||
})); | ||
|
||
export const projects = pgTable('projects', { | ||
id: uuid("id").primaryKey().defaultRandom(), | ||
project_name: varchar("project_name", { length: 255 }).notNull(), | ||
url: varchar("url").notNull(), | ||
private: boolean("private").notNull(), | ||
authorId: integer("user_id") | ||
}); | ||
|
||
export const projectRelations = relations(projects, ({ one }) => ({ | ||
user: one(users, { | ||
fields: [projects.authorId], | ||
references: [users.id] | ||
}), | ||
})); |
Oops, something went wrong.