refactor(lst): register added in
This commit is contained in:
175
server/database/.gitignore
vendored
175
server/database/.gitignore
vendored
@@ -1,175 +0,0 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Caches
|
||||
|
||||
.cache
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.*
|
||||
|
||||
# IntelliJ based IDEs
|
||||
.idea
|
||||
|
||||
# Finder (MacOS) folder config
|
||||
.DS_Store
|
||||
@@ -1,15 +0,0 @@
|
||||
# database
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
|
||||
This project was created using `bun init` in bun v1.2.2. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
|
||||
7
server/database/dbClient.ts
Normal file
7
server/database/dbClient.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import {drizzle} from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
const database = process.env.DATABASE_URL || "";
|
||||
|
||||
const queryClient = postgres(database);
|
||||
|
||||
export const db = drizzle({client: queryClient});
|
||||
@@ -1,8 +0,0 @@
|
||||
import {defineConfig} from "drizzle-kit";
|
||||
export default defineConfig({
|
||||
dialect: "postgresql", // 'mysql' | 'sqlite' | 'turso'
|
||||
schema: "./schema",
|
||||
dbCredentials: {
|
||||
url: "postgresql://postgres:nova0511@localhost:5432/lst_db",
|
||||
},
|
||||
});
|
||||
@@ -1,12 +0,0 @@
|
||||
CREATE TABLE "users" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"user_id" text NOT NULL,
|
||||
"title" text NOT NULL,
|
||||
"passwordToken" text NOT NULL,
|
||||
"passwordTokenExpires" timestamp,
|
||||
"active" boolean DEFAULT true NOT NULL,
|
||||
"pingcode" numeric,
|
||||
"add_Date" timestamp DEFAULT now(),
|
||||
"add_User" text DEFAULT 'LST_System' NOT NULL,
|
||||
"upd_date" timestamp DEFAULT now()
|
||||
);
|
||||
@@ -1,13 +0,0 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1739914245651,
|
||||
"tag": "0000_stormy_thunderbolt",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import {drizzle} from "drizzle-orm/postgres-js";
|
||||
import postgres from "postgres";
|
||||
import "../../load-env";
|
||||
|
||||
const queryClient = postgres("postgresql://postgres:nova0511@localhost:5432/lst_db");
|
||||
|
||||
export const db = drizzle(queryClient);
|
||||
15
server/database/migrations/0000_typical_frightful_four.sql
Normal file
15
server/database/migrations/0000_typical_frightful_four.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE "users" (
|
||||
"user_id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"username" text NOT NULL,
|
||||
"email" text NOT NULL,
|
||||
"password" text NOT NULL,
|
||||
"passwordToken" text,
|
||||
"passwordTokenExpires" timestamp,
|
||||
"active" boolean DEFAULT true NOT NULL,
|
||||
"pingcode" numeric,
|
||||
"lastLogin" timestamp DEFAULT now(),
|
||||
"add_User" text DEFAULT 'LST_System' NOT NULL,
|
||||
"add_Date" timestamp DEFAULT now(),
|
||||
"upd_User" text DEFAULT 'LST_System' NOT NULL,
|
||||
"upd_date" timestamp DEFAULT now()
|
||||
);
|
||||
1
server/database/migrations/0001_sharp_pet_avengers.sql
Normal file
1
server/database/migrations/0001_sharp_pet_avengers.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE UNIQUE INDEX "username" ON "users" USING btree ("username");
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"id": "d0e2effa-c6ac-4f81-b546-ef6b10037eca",
|
||||
"id": "d1b4a8a6-caa3-4c45-a3a1-cdfc99ca7bea",
|
||||
"prevId": "00000000-0000-0000-0000-000000000000",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
@@ -8,20 +8,27 @@
|
||||
"name": "users",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"title": {
|
||||
"name": "title",
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"password": {
|
||||
"name": "password",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
@@ -30,7 +37,7 @@
|
||||
"name": "passwordToken",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
"notNull": false
|
||||
},
|
||||
"passwordTokenExpires": {
|
||||
"name": "passwordTokenExpires",
|
||||
@@ -51,8 +58,8 @@
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"lastLogin": {
|
||||
"name": "lastLogin",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
@@ -65,6 +72,20 @@
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
133
server/database/migrations/meta/0001_snapshot.json
Normal file
133
server/database/migrations/meta/0001_snapshot.json
Normal file
@@ -0,0 +1,133 @@
|
||||
{
|
||||
"id": "d6c99236-0eea-49f1-817b-13139c0f42f5",
|
||||
"prevId": "d1b4a8a6-caa3-4c45-a3a1-cdfc99ca7bea",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
"public.users": {
|
||||
"name": "users",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"user_id": {
|
||||
"name": "user_id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true,
|
||||
"default": "gen_random_uuid()"
|
||||
},
|
||||
"username": {
|
||||
"name": "username",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"email": {
|
||||
"name": "email",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"password": {
|
||||
"name": "password",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true
|
||||
},
|
||||
"passwordToken": {
|
||||
"name": "passwordToken",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"passwordTokenExpires": {
|
||||
"name": "passwordTokenExpires",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"active": {
|
||||
"name": "active",
|
||||
"type": "boolean",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": true
|
||||
},
|
||||
"pingcode": {
|
||||
"name": "pingcode",
|
||||
"type": "numeric",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"lastLogin": {
|
||||
"name": "lastLogin",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"add_User": {
|
||||
"name": "add_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"add_Date": {
|
||||
"name": "add_Date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
},
|
||||
"upd_User": {
|
||||
"name": "upd_User",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": true,
|
||||
"default": "'LST_System'"
|
||||
},
|
||||
"upd_date": {
|
||||
"name": "upd_date",
|
||||
"type": "timestamp",
|
||||
"primaryKey": false,
|
||||
"notNull": false,
|
||||
"default": "now()"
|
||||
}
|
||||
},
|
||||
"indexes": {
|
||||
"username": {
|
||||
"name": "username",
|
||||
"columns": [
|
||||
{
|
||||
"expression": "username",
|
||||
"isExpression": false,
|
||||
"asc": true,
|
||||
"nulls": "last"
|
||||
}
|
||||
],
|
||||
"isUnique": true,
|
||||
"concurrently": false,
|
||||
"method": "btree",
|
||||
"with": {}
|
||||
}
|
||||
},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"sequences": {},
|
||||
"roles": {},
|
||||
"policies": {},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
||||
20
server/database/migrations/meta/_journal.json
Normal file
20
server/database/migrations/meta/_journal.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"entries": [
|
||||
{
|
||||
"idx": 0,
|
||||
"version": "7",
|
||||
"when": 1740160921910,
|
||||
"tag": "0000_typical_frightful_four",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1740161259149,
|
||||
"tag": "0001_sharp_pet_avengers",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
{
|
||||
"name": "database",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"@types/pg": "^8.11.11",
|
||||
"drizzle-kit": "^0.30.4",
|
||||
"tsx": "^4.19.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"drizzle-orm": "^0.39.3",
|
||||
"drizzle-zod": "^0.7.0",
|
||||
"pg": "^8.13.3",
|
||||
"postgres": "^3.4.5"
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,35 @@
|
||||
import {text, pgTable, serial, numeric, index, timestamp, boolean} from "drizzle-orm/pg-core";
|
||||
import {text, pgTable, numeric, index, timestamp, boolean, uuid, uniqueIndex} from "drizzle-orm/pg-core";
|
||||
import {createInsertSchema, createSelectSchema} from "drizzle-zod";
|
||||
import {z} from "zod";
|
||||
|
||||
export const users = pgTable("users", {
|
||||
user_id: serial("id").primaryKey(),
|
||||
username: text("user_id").notNull(),
|
||||
email: text("title").notNull(),
|
||||
passwordToken: text("passwordToken").notNull(),
|
||||
passwordTokenExpires: timestamp("passwordTokenExpires"),
|
||||
acitve: boolean("active").default(true).notNull(),
|
||||
pinCode: numeric("pingcode"),
|
||||
lastLogin: timestamp("add_Date").defaultNow(),
|
||||
add_User: text("add_User").default("LST_System").notNull(),
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
upd_user: text("add_User").default("LST_System").notNull(),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
});
|
||||
export const users = pgTable(
|
||||
"users",
|
||||
{
|
||||
user_id: uuid("user_id").defaultRandom().primaryKey(),
|
||||
username: text("username").notNull(),
|
||||
email: text("email").notNull(),
|
||||
password: text("password").notNull(),
|
||||
passwordToken: text("passwordToken"),
|
||||
passwordTokenExpires: timestamp("passwordTokenExpires"),
|
||||
acitve: boolean("active").default(true).notNull(),
|
||||
pinCode: numeric("pingcode"),
|
||||
lastLogin: timestamp("lastLogin").defaultNow(),
|
||||
add_User: text("add_User").default("LST_System").notNull(),
|
||||
add_Date: timestamp("add_Date").defaultNow(),
|
||||
upd_user: text("upd_User").default("LST_System").notNull(),
|
||||
upd_date: timestamp("upd_date").defaultNow(),
|
||||
},
|
||||
(table) => [
|
||||
// uniqueIndex('emailUniqueIndex').on(sql`lower(${table.email})`),
|
||||
uniqueIndex("username").on(table.username),
|
||||
]
|
||||
);
|
||||
|
||||
// Schema for inserting a user - can be used to validate API requests
|
||||
export const insertUsersSchema = createInsertSchema(users, {
|
||||
username: z.string().min(3, {message: "Username must be at least 3 characters"}),
|
||||
email: z.string().email({message: "Invalid email"}),
|
||||
passwordToken: z.string().min(8, {message: "Password must be at least 8 characters"}),
|
||||
password: z.string().min(8, {message: "Password must be at least 8 characters"}),
|
||||
});
|
||||
// Schema for selecting a Expenses - can be used to validate API responses
|
||||
export const selectExpensesSchema = createSelectSchema(users);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user