初始化项目

This commit is contained in:
wmp
2025-09-13 14:00:56 +08:00
commit f1fa28401e
61 changed files with 4710 additions and 0 deletions

16
prisma/prisma.config.ts Normal file
View File

@@ -0,0 +1,16 @@
import { PrismaClient } from '@prisma/client'
declare global {
var cachedPrisma: PrismaClient
}
export let prisma: PrismaClient
if (process.env.NODE_ENV === 'production') {
prisma = new PrismaClient()
} else {
if (!global.cachedPrisma) {
global.cachedPrisma = new PrismaClient()
}
prisma = global.cachedPrisma
}

160
prisma/schema.prisma Normal file
View File

@@ -0,0 +1,160 @@
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "debian-openssl-3.0.x"]
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model change {
id Int @id @default(autoincrement())
time DateTime? @db.Timestamp(0)
city Int?
macaddr String @db.VarChar(20)
edge_new String @db.VarChar(20)
edge_old String? @db.VarChar(20)
info String @db.VarChar(500)
network String @db.VarChar(20)
createtime DateTime @default(now()) @db.DateTime(0)
@@index([edge_new], map: "edge_new")
@@index([time], map: "change_time_index")
}
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model cityhash {
id Int @id @default(autoincrement()) @db.UnsignedInt
macaddr String? @db.VarChar(20)
city String @db.VarChar(20)
num Int
hash String @db.VarChar(100)
label String? @db.VarChar(20)
count Int @default(0)
offset Int @default(0)
createtime DateTime @default(now()) @db.DateTime(0)
updatetime DateTime @default(now()) @db.DateTime(0)
}
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model edge {
id Int @id @default(autoincrement())
macaddr String @unique(map: "edge_macaddr_idx") @db.VarChar(17)
public String @db.VarChar(255)
isp String @db.VarChar(255)
single Boolean
sole Boolean
arch Boolean
online Int @default(0)
city_id Int
active Boolean
@@index([active], map: "edge_active_index")
@@index([city_id])
@@index([isp], map: "edge_isp_index")
@@index([public], map: "edge_public_index")
}
model gateway {
id Int @id @default(autoincrement()) @db.UnsignedInt
macaddr String @db.VarChar(20)
table Int
edge String @db.VarChar(20)
network String @db.VarChar(20)
cityhash String @db.VarChar(100)
label String? @db.VarChar(20)
user String? @db.VarChar(20)
inner_ip String? @db.VarChar(20)
ischange Int @default(0) @db.TinyInt
isonline Int @default(0) @db.TinyInt
onlinenum Int @default(0)
createtime DateTime @default(now()) @db.DateTime(0)
updatetime DateTime @default(now()) @db.DateTime(0)
@@index([inner_ip], map: "inner_ip")
}
/// This model or at least one of its fields has comments in the database, and requires an additional setup for migrations: Read more: https://pris.ly/d/database-comments
model token {
id Int @id @default(autoincrement()) @db.UnsignedInt
setid Int @default(1)
change_count Int
limit_count Int @default(32000)
token String @db.VarChar(1000)
macaddr String @db.VarChar(100)
token_time DateTime @db.DateTime(0)
inner_ip String? @db.VarChar(20)
l2ip String? @db.VarChar(20)
enable Boolean @default(true)
createtime DateTime @default(now()) @db.DateTime(0)
updatetime DateTime @default(now()) @db.DateTime(0)
}
model change_city {
id Int @id @default(autoincrement())
time DateTime? @db.Timestamp(0)
city_id Int?
count Int?
offset_old Int?
offset_new Int?
@@index([time], map: "change_city_time_index")
}
model Account {
id String @id @default(cuid())
userId Int @map("user_id")
type String
provider String
providerAccountId String @map("provider_account_id")
refresh_token String? @db.Text
access_token String? @db.Text
expires_at Int?
token_type String?
scope String?
id_token String? @db.Text
session_state String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@unique([provider, providerAccountId])
@@map("accounts")
}
model User {
id Int @id @default(autoincrement())
phone String @unique
password String
name String?
verifiedPhone Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
sessions Session[]
accounts Account[]
@@map("users")
}
model Session {
id String @id
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
expires DateTime
createdAt DateTime @default(now())
@@index([userId])
@@map("sessions")
}
model VerificationCode {
id Int @id @default(autoincrement())
phone String
code String
type String
expiresAt DateTime
createdAt DateTime @default(now())
@@index([phone, type])
@@map("verification_codes")
}

48
prisma/seed.ts Normal file
View File

@@ -0,0 +1,48 @@
import { PrismaClient } from '@prisma/client'
import { hash } from 'bcryptjs'
const prisma = new PrismaClient()
async function main() {
console.log('🚀 开始执行种子脚本...')
try {
// 首先检查用户是否已存在
const existingUser = await prisma.user.findUnique({
where: { phone: '17516219072' }
})
if (existingUser) {
console.log('✅ 用户已存在:', existingUser)
return
}
console.log('🔐 加密密码...')
const password = await hash('123456', 10)
console.log('✅ 加密完成')
console.log('👤 创建用户...')
const user = await prisma.user.create({
data: {
phone: '17516219072',
password: password,
name: '测试用户',
},
})
console.log('✅ 用户创建成功:', user)
} catch (error) {
console.error('❌ 种子脚本错误:', error)
throw error
}
}
main()
.catch((e) => {
console.error('❌ 种子脚本执行失败:', e)
process.exit(1)
})
.finally(async () => {
await prisma.$disconnect()
console.log('🔚 数据库连接已关闭')
})