Skip to content

Commit 2e89e6f

Browse files
authored
Merge pull request #6 from CS3219-AY2425S1/PEER-204-Schema-For-User-Registration
Adding Schema for User Account Registration
2 parents 2f522d8 + da33230 commit 2e89e6f

File tree

5 files changed

+108
-5
lines changed

5 files changed

+108
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE IF NOT EXISTS "users" (
2+
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
3+
"email" varchar(255) NOT NULL,
4+
"username" varchar(255) NOT NULL,
5+
"first_name" varchar(255) NOT NULL,
6+
"last_name" varchar(255) NOT NULL,
7+
"password" varchar(255) NOT NULL,
8+
CONSTRAINT "users_email_unique" UNIQUE("email"),
9+
CONSTRAINT "users_username_unique" UNIQUE("username")
10+
);
11+
--> statement-breakpoint
12+
DROP TABLE "tableName";
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"id": "ecf4404b-9642-42c5-b6d6-deeaeaca7a77",
3+
"prevId": "bfb0f47d-1ebe-47d4-b979-8fe9d6305cd4",
4+
"version": "7",
5+
"dialect": "postgresql",
6+
"tables": {
7+
"public.users": {
8+
"name": "users",
9+
"schema": "",
10+
"columns": {
11+
"id": {
12+
"name": "id",
13+
"type": "uuid",
14+
"primaryKey": true,
15+
"notNull": true,
16+
"default": "gen_random_uuid()"
17+
},
18+
"email": {
19+
"name": "email",
20+
"type": "varchar(255)",
21+
"primaryKey": false,
22+
"notNull": true
23+
},
24+
"username": {
25+
"name": "username",
26+
"type": "varchar(255)",
27+
"primaryKey": false,
28+
"notNull": true
29+
},
30+
"first_name": {
31+
"name": "first_name",
32+
"type": "varchar(255)",
33+
"primaryKey": false,
34+
"notNull": true
35+
},
36+
"last_name": {
37+
"name": "last_name",
38+
"type": "varchar(255)",
39+
"primaryKey": false,
40+
"notNull": true
41+
},
42+
"password": {
43+
"name": "password",
44+
"type": "varchar(255)",
45+
"primaryKey": false,
46+
"notNull": true
47+
}
48+
},
49+
"indexes": {},
50+
"foreignKeys": {},
51+
"compositePrimaryKeys": {},
52+
"uniqueConstraints": {
53+
"users_email_unique": {
54+
"name": "users_email_unique",
55+
"nullsNotDistinct": false,
56+
"columns": [
57+
"email"
58+
]
59+
},
60+
"users_username_unique": {
61+
"name": "users_username_unique",
62+
"nullsNotDistinct": false,
63+
"columns": [
64+
"username"
65+
]
66+
}
67+
}
68+
}
69+
},
70+
"enums": {},
71+
"schemas": {},
72+
"sequences": {},
73+
"_meta": {
74+
"columns": {},
75+
"schemas": {},
76+
"tables": {}
77+
}
78+
}

backend/user/drizzle/meta/_journal.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"when": 1726382290778,
99
"tag": "0000_initial_schema",
1010
"breakpoints": true
11+
},
12+
{
13+
"idx": 1,
14+
"version": "7",
15+
"when": 1726678203279,
16+
"tag": "0001_clammy_grandmaster",
17+
"breakpoints": true
1118
}
1219
]
1320
}

backend/user/src/lib/db/schema.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import { pgTable, uuid } from 'drizzle-orm/pg-core';
1+
import { pgTable, uuid, varchar } from 'drizzle-orm/pg-core';
22

3-
export const tableName = pgTable('tableName', {
4-
id: uuid('id').unique().primaryKey().defaultRandom(),
3+
// Define the user table
4+
export const users = pgTable('users', {
5+
id: uuid('id').primaryKey().defaultRandom(), // UUID as primary key with a default random value
6+
email: varchar('email', { length: 255 }).unique().notNull(), // Email field, unique and required
7+
username: varchar('username', { length: 255 }).unique().notNull(), // Username field, unique and required
8+
firstName: varchar('first_name', { length: 255 }).notNull(), // First name field, required
9+
lastName: varchar('last_name', { length: 255 }).notNull(), // Last name field, required
10+
password: varchar('password', { length: 255 }).notNull(), // Password field, required (hashed password)
511
});

backend/user/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express, { json } from 'express';
22
import pino from 'pino-http';
3-
import { db, tableName } from './lib/db';
3+
import { db, users } from './lib/db';
44

55
const app = express();
66
app.use(pino());
@@ -14,7 +14,7 @@ app.get('/', async (_req, res) => {
1414

1515
// Ensure DB service is up before running.
1616
app.get('/test-db', async (_req, res) => {
17-
await db.select().from(tableName);
17+
await db.select().from(users);
1818
res.json({ message: 'OK ' });
1919
});
2020

0 commit comments

Comments
 (0)