Skip to content

Commit

Permalink
Merge pull request #10 from Manudasari265/feat/express-server
Browse files Browse the repository at this point in the history
feat:(db)/added projects schema
  • Loading branch information
Manudasari265 authored Feb 28, 2025
2 parents da75b6b + 0ae7176 commit 2895b92
Show file tree
Hide file tree
Showing 12 changed files with 589 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
"typescript": "^5.7.3"
},
"dependencies": {
"@repo/typescript-config": "workspace:*",
"@clerk/express": "^1.3.50",
"@repo/db": "workspace:*",
"@repo/typescript-config": "workspace:*",
"dotenv": "^16.4.7",
"ts-node": "^10.9.2",
"zod": "^3.24.2"
Expand Down
12 changes: 10 additions & 2 deletions apps/services/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import { db } from "@repo/db/client";
import { user } from "@repo/db/user";

dotenv.config();

const app = express();
const PORT = 3001;
const PORT = process.env.PORT || 3001;

app.use(cors());
app.use(express.json());
app.use(cors({
origin: ["http://localhost:3000"],
credentials: true,
methods: ["POST", "PUT", "GET", "DELETE", "OPTIONS"],
allowedHeaders: ["Content-Type", "Authorization"]
}));

//^ TODO: database connection is failing - fix this
//^ TODO: port mapping config failing - fix this
Expand Down
5 changes: 5 additions & 0 deletions apps/services/types.d.ts
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 packages/db/drizzle/migrations/0002_curvy_blazing_skull.sql
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;
130 changes: 130 additions & 0 deletions packages/db/drizzle/migrations/meta/0002_snapshot.json
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": {}
}
}
7 changes: 7 additions & 0 deletions packages/db/drizzle/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1740570184049,
"tag": "0001_white_dreaming_celestial",
"breakpoints": true
},
{
"idx": 2,
"version": "7",
"when": 1740742872789,
"tag": "0002_curvy_blazing_skull",
"breakpoints": true
}
]
}
28 changes: 25 additions & 3 deletions packages/db/src/db/schema.ts
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]
}),
}));
Loading

0 comments on commit 2895b92

Please sign in to comment.