Init applications
This commit is contained in:
7
database/common.ts
Normal file
7
database/common.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { serial, timestamp } from "drizzle-orm/pg-core";
|
||||
|
||||
export const id = serial("id").primaryKey();
|
||||
|
||||
export const createdAt = timestamp("created_at").defaultNow().notNull();
|
||||
export const updatedAt = timestamp("updated_at").defaultNow()
|
||||
.$onUpdate(() => new Date()).notNull();
|
||||
74
database/schema/auth.db.ts
Normal file
74
database/schema/auth.db.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import { pgTable, text, timestamp, boolean } from "drizzle-orm/pg-core";
|
||||
|
||||
export const user = pgTable("user", {
|
||||
id: text("id").primaryKey(),
|
||||
name: text("name").notNull(),
|
||||
email: text("email").notNull().unique(),
|
||||
emailVerified: boolean("email_verified").default(false).notNull(),
|
||||
image: text("image"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.defaultNow()
|
||||
.$onUpdate(() => /* @__PURE__ */ new Date())
|
||||
.notNull(),
|
||||
username: text("username").unique(),
|
||||
displayUsername: text("display_username"),
|
||||
phoneNumber: text("phone_number").unique(),
|
||||
phoneNumberVerified: boolean("phone_number_verified"),
|
||||
role: text("role").default("user"),
|
||||
lang: text("lang").default("en"),
|
||||
});
|
||||
|
||||
export const session = pgTable("session", {
|
||||
id: text("id").primaryKey(),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
token: text("token").notNull().unique(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
ipAddress: text("ip_address"),
|
||||
userAgent: text("user_agent"),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
});
|
||||
|
||||
export const account = pgTable("account", {
|
||||
id: text("id").primaryKey(),
|
||||
accountId: text("account_id").notNull(),
|
||||
providerId: text("provider_id").notNull(),
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
accessToken: text("access_token"),
|
||||
refreshToken: text("refresh_token"),
|
||||
idToken: text("id_token"),
|
||||
accessTokenExpiresAt: timestamp("access_token_expires_at"),
|
||||
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
|
||||
scope: text("scope"),
|
||||
password: text("password"),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
export const verification = pgTable("verification", {
|
||||
id: text("id").primaryKey(),
|
||||
identifier: text("identifier").notNull(),
|
||||
value: text("value").notNull(),
|
||||
expiresAt: timestamp("expires_at").notNull(),
|
||||
createdAt: timestamp("created_at").defaultNow().notNull(),
|
||||
updatedAt: timestamp("updated_at")
|
||||
.defaultNow()
|
||||
.$onUpdate(() => new Date())
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
export const jwks = pgTable("jwks", {
|
||||
id: text("id").primaryKey(),
|
||||
publicKey: text("public_key").notNull(),
|
||||
privateKey: text("private_key").notNull(),
|
||||
createdAt: timestamp("created_at").notNull(),
|
||||
});
|
||||
14
database/schema/basic.db.ts
Normal file
14
database/schema/basic.db.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { pgTable, text, varchar } from "drizzle-orm/pg-core";
|
||||
import { createdAt, id, updatedAt } from "../common";
|
||||
|
||||
|
||||
export const attributeFile = pgTable("nvwa_attribute_file", {
|
||||
id,
|
||||
name: varchar("name", { length: 255 }).notNull(),
|
||||
type: varchar("type", { length: 255 }).notNull(),
|
||||
description: text("description"),
|
||||
url: varchar("url", { length: 255 }),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
});
|
||||
|
||||
38
database/schema/project.db.ts
Normal file
38
database/schema/project.db.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
bigint, // BIGINT (大整数, -2^63 到 2^63-1)
|
||||
bigserial, // BIGSERIAL (自增大整数, 1 到 2^63-1)
|
||||
boolean, // BOOLEAN (布尔值)
|
||||
char, // CHAR (定长字符串)
|
||||
check, // 定义检查约束
|
||||
date, // DATE (日期)
|
||||
decimal, // DECIMAL/NUMERIC (精确数字, 指定 precision 和 scale)
|
||||
doublePrecision, // DOUBLE PRECISION (双精度浮点数, 8字节)
|
||||
foreignKey, // 定义外键
|
||||
index, // 创建索引
|
||||
integer, // INTEGER (整数, -2^31 到 2^31-1)
|
||||
interval, // INTERVAL (时间间隔)
|
||||
json, // JSON (JSON 数据)
|
||||
jsonb, // JSONB (二进制 JSON, 推荐使用)
|
||||
numeric, // NUMERIC (同 decimal)
|
||||
pgEnum, // 定义枚举类型 (PostgreSQL ENUM)
|
||||
pgMaterializedView, // 创建物化视图
|
||||
pgPolicy, // 定义行级安全策略
|
||||
pgRole, // 定义角色
|
||||
pgSequence, // 创建序列
|
||||
pgTable, // 定义表
|
||||
pgTableCreator, // 创建自定义表名生成器的表定义函数
|
||||
pgView, // 创建视图
|
||||
primaryKey, // 定义主键
|
||||
serial, // SERIAL (自增整数, 1 到 2^31-1)
|
||||
text, // TEXT (变长字符串, 无长度限制)
|
||||
time, // TIME (时间)
|
||||
timestamp, // TIMESTAMP (日期时间, 无时区)
|
||||
unique, // 定义唯一约束
|
||||
uniqueIndex, // 创建唯一索引
|
||||
uuid, // UUID (通用唯一标识符)
|
||||
varchar, // VARCHAR (变长字符串, 指定长度)
|
||||
} from "drizzle-orm/pg-core";
|
||||
|
||||
import { sql } from "drizzle-orm";
|
||||
|
||||
import { id, createdAt, updatedAt } from "../common";
|
||||
Reference in New Issue
Block a user