From a592c18ba3a7a7324884fe0a0f086766666bf004 Mon Sep 17 00:00:00 2001 From: kennethcheng Date: Mon, 27 Apr 2026 19:03:15 +0800 Subject: [PATCH] =?UTF-8?q?fix(db):=20=E4=BF=AE=E5=A4=8D=20localhost=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E9=97=AE=E9=A2=98=E5=B9=B6=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=9F=BA=E7=A1=80=E6=9E=B6=E6=9E=84=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- drizzle.config.ts | 3 ++ drizzle/0000_abandoned_titania.sql | 7 ++++ drizzle/meta/0000_snapshot.json | 66 ++++++++++++++++++++++++++++++ drizzle/meta/_journal.json | 13 ++++++ src/db/schema.ts | 10 +++++ 5 files changed, 99 insertions(+) create mode 100644 drizzle/0000_abandoned_titania.sql create mode 100644 drizzle/meta/0000_snapshot.json create mode 100644 drizzle/meta/_journal.json create mode 100644 src/db/schema.ts diff --git a/drizzle.config.ts b/drizzle.config.ts index 1c6dea1..886638f 100644 --- a/drizzle.config.ts +++ b/drizzle.config.ts @@ -1,4 +1,7 @@ import { defineConfig } from "drizzle-kit"; +import dotenv from "dotenv"; + +dotenv.config(); export default { schema: "./src/db/schema.ts", diff --git a/drizzle/0000_abandoned_titania.sql b/drizzle/0000_abandoned_titania.sql new file mode 100644 index 0000000..ec72669 --- /dev/null +++ b/drizzle/0000_abandoned_titania.sql @@ -0,0 +1,7 @@ +CREATE TABLE "users" ( + "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "username" varchar(50) NOT NULL, + "password_hash" varchar(255) NOT NULL, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + CONSTRAINT "users_username_unique" UNIQUE("username") +); diff --git a/drizzle/meta/0000_snapshot.json b/drizzle/meta/0000_snapshot.json new file mode 100644 index 0000000..041a853 --- /dev/null +++ b/drizzle/meta/0000_snapshot.json @@ -0,0 +1,66 @@ +{ + "id": "1fc34e1e-d311-443f-bd56-87246c2025ea", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "username": { + "name": "username", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json new file mode 100644 index 0000000..143050b --- /dev/null +++ b/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1777286818794, + "tag": "0000_abandoned_titania", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/db/schema.ts b/src/db/schema.ts new file mode 100644 index 0000000..f1809f3 --- /dev/null +++ b/src/db/schema.ts @@ -0,0 +1,10 @@ +import { pgTable, uuid, varchar, timestamp } from "drizzle-orm/pg-core"; + +export const users = pgTable("users", { + id: uuid("id").primaryKey().defaultRandom(), + username: varchar("username", { length: 50 }).notNull().unique(), + passwordHash: varchar("password_hash", { length: 255 }).notNull(), + createdAt: timestamp("created_at", { withTimezone: true, mode: "date" }) + .defaultNow() + .notNull(), +});