From c49faab6ae2b4f7fce15b387d15c0a5f3baf1d3b Mon Sep 17 00:00:00 2001 From: TZGyn Date: Mon, 13 Nov 2023 12:59:37 +0800 Subject: [PATCH] update db schema and reset db --- ..._brock.sql => 0000_nebulous_energizer.sql} | 13 +- drizzle/0001_sudden_nightmare.sql | 7 - drizzle/meta/0000_snapshot.json | 47 ++++- drizzle/meta/0001_snapshot.json | 174 ------------------ drizzle/meta/_journal.json | 11 +- src/lib/db/schema.ts | 6 +- 6 files changed, 57 insertions(+), 201 deletions(-) rename drizzle/{0000_bored_eddie_brock.sql => 0000_nebulous_energizer.sql} (65%) delete mode 100644 drizzle/0001_sudden_nightmare.sql delete mode 100644 drizzle/meta/0001_snapshot.json diff --git a/drizzle/0000_bored_eddie_brock.sql b/drizzle/0000_nebulous_energizer.sql similarity index 65% rename from drizzle/0000_bored_eddie_brock.sql rename to drizzle/0000_nebulous_energizer.sql index 41f9e58..ac62bbd 100644 --- a/drizzle/0000_bored_eddie_brock.sql +++ b/drizzle/0000_nebulous_energizer.sql @@ -1,3 +1,9 @@ +CREATE TABLE IF NOT EXISTS "session" ( + "token" varchar(255) NOT NULL, + "user_id" integer NOT NULL, + "expires" timestamp NOT NULL +); +--> statement-breakpoint CREATE TABLE IF NOT EXISTS "shortener" ( "id" serial PRIMARY KEY NOT NULL, "link" varchar(255) NOT NULL, @@ -7,11 +13,12 @@ CREATE TABLE IF NOT EXISTS "shortener" ( --> statement-breakpoint CREATE TABLE IF NOT EXISTS "user" ( "id" serial PRIMARY KEY NOT NULL, - "uuid" text NOT NULL, + "uuid" uuid DEFAULT gen_random_uuid(), "email" varchar(255) NOT NULL, - "username" varchar(255) NOT NULL, + "username" varchar(255), "password" varchar(255) NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL + "created_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "user_email_unique" UNIQUE("email") ); --> statement-breakpoint CREATE TABLE IF NOT EXISTS "visitor" ( diff --git a/drizzle/0001_sudden_nightmare.sql b/drizzle/0001_sudden_nightmare.sql deleted file mode 100644 index a3ad0df..0000000 --- a/drizzle/0001_sudden_nightmare.sql +++ /dev/null @@ -1,7 +0,0 @@ -CREATE TABLE IF NOT EXISTS "session" ( - "token" varchar(255) NOT NULL, - "user_id" integer NOT NULL, - "expires" timestamp NOT NULL -); ---> statement-breakpoint -ALTER TABLE "user" ADD CONSTRAINT "user_email_unique" UNIQUE("email"); \ No newline at end of file diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json index 2915846..9fc7a76 100644 --- a/drizzle/meta/0000_snapshot.json +++ b/drizzle/meta/0000_snapshot.json @@ -1,9 +1,37 @@ { - "id": "1098bf22-b657-4c36-b85c-51f1a8f6e36d", + "id": "9d44b46b-3e93-4782-8750-dbf39513bb0c", "prevId": "00000000-0000-0000-0000-000000000000", "version": "5", "dialect": "pg", "tables": { + "session": { + "name": "session", + "schema": "", + "columns": { + "token": { + "name": "token", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, "shortener": { "name": "shortener", "schema": "", @@ -51,9 +79,10 @@ }, "uuid": { "name": "uuid", - "type": "text", + "type": "uuid", "primaryKey": false, - "notNull": true + "notNull": false, + "default": "gen_random_uuid()" }, "email": { "name": "email", @@ -65,7 +94,7 @@ "name": "username", "type": "varchar(255)", "primaryKey": false, - "notNull": true + "notNull": false }, "password": { "name": "password", @@ -84,7 +113,15 @@ "indexes": {}, "foreignKeys": {}, "compositePrimaryKeys": {}, - "uniqueConstraints": {} + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + } }, "visitor": { "name": "visitor", diff --git a/drizzle/meta/0001_snapshot.json b/drizzle/meta/0001_snapshot.json deleted file mode 100644 index ea5252d..0000000 --- a/drizzle/meta/0001_snapshot.json +++ /dev/null @@ -1,174 +0,0 @@ -{ - "id": "7c7bf598-99e4-405b-a089-065b8e8226fa", - "prevId": "1098bf22-b657-4c36-b85c-51f1a8f6e36d", - "version": "5", - "dialect": "pg", - "tables": { - "session": { - "name": "session", - "schema": "", - "columns": { - "token": { - "name": "token", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "expires": { - "name": "expires", - "type": "timestamp", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "shortener": { - "name": "shortener", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "link": { - "name": "link", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "code": { - "name": "code", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "uuid": { - "name": "uuid", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "username": { - "name": "username", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - }, - "visitor": { - "name": "visitor", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "shortener_id": { - "name": "shortener_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "country_code": { - "name": "country_code", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "country": { - "name": "country", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - } -} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 996435a..f422b61 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -5,15 +5,8 @@ { "idx": 0, "version": "5", - "when": 1699648628603, - "tag": "0000_bored_eddie_brock", - "breakpoints": true - }, - { - "idx": 1, - "version": "5", - "when": 1699649369484, - "tag": "0001_sudden_nightmare", + "when": 1699851315914, + "tag": "0000_nebulous_energizer", "breakpoints": true } ] diff --git a/src/lib/db/schema.ts b/src/lib/db/schema.ts index 80f18f8..39d304e 100644 --- a/src/lib/db/schema.ts +++ b/src/lib/db/schema.ts @@ -3,8 +3,8 @@ import { serial, varchar, timestamp, - text, integer, + uuid, } from 'drizzle-orm/pg-core'; import { relations } from 'drizzle-orm'; @@ -18,9 +18,9 @@ export const shortener = pgTable('shortener', { export const user = pgTable('user', { id: serial('id').primaryKey().notNull(), - uuid: text('uuid').notNull(), + uuid: uuid('uuid').defaultRandom(), email: varchar('email', { length: 255 }).notNull().unique(), - username: varchar('username', { length: 255 }).notNull(), + username: varchar('username', { length: 255 }), password: varchar('password', { length: 255 }).notNull(), createdAt: timestamp('created_at', { mode: 'string' }).defaultNow().notNull(), });