initial
This commit is contained in:
88
src/schema.ts
Normal file
88
src/schema.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
import {
|
||||
sqliteTable,
|
||||
text,
|
||||
integer,
|
||||
uniqueIndex,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
|
||||
//----------------User
|
||||
export const user = sqliteTable("users", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
phone: text("phone").unique().notNull(),
|
||||
email: text("email"),
|
||||
job: text("job").notNull(),
|
||||
education: text("education").notNull(),
|
||||
vision: text("vision"),
|
||||
reason: text("reason"),
|
||||
group: integer("group_id")
|
||||
.references(() => group.id)
|
||||
.notNull(),
|
||||
});
|
||||
|
||||
export const userRelation = relations(user, ({ many, one }) => ({
|
||||
opinions: many(userOpinion),
|
||||
group: one(group, {
|
||||
fields: [user.group],
|
||||
references: [group.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
//----------------Group
|
||||
export const group = sqliteTable("groups", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name"),
|
||||
});
|
||||
|
||||
export const groupRelation = relations(group, ({ many }) => ({
|
||||
users: many(user),
|
||||
}));
|
||||
|
||||
//----------------Opinion
|
||||
export const opinion = sqliteTable("opinions", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name"),
|
||||
type: text("type", { enum: ["3Choice", "4Choice"] }),
|
||||
});
|
||||
|
||||
//----------------UserOpinion
|
||||
export const userOpinion = sqliteTable("user_opinions", {
|
||||
userId: integer("user_id").references(() => user.id),
|
||||
opinionId: integer("opinion_id").references(() => opinion.id),
|
||||
choice: text("choice", {
|
||||
enum: ["agree", "disagree", "deciding", "ignore"],
|
||||
}).default("ignore"),
|
||||
});
|
||||
|
||||
export const userOpinionRelation = relations(userOpinion, ({ one }) => ({
|
||||
user: one(user, {
|
||||
fields: [userOpinion.userId],
|
||||
references: [user.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
//----------------Zone
|
||||
export const zone = sqliteTable("zones", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
province: integer("province_id")
|
||||
.notNull()
|
||||
.references(() => province.id),
|
||||
});
|
||||
export const zoneRelation = relations(zone, ({ one }) => ({
|
||||
province: one(province, {
|
||||
fields: [zone.province],
|
||||
references: [province.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
//----------------Province
|
||||
export const province = sqliteTable("provinces", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
});
|
||||
|
||||
export const provinceRelation = relations(province, ({ many }) => ({
|
||||
province: many(zone),
|
||||
}));
|
||||
Reference in New Issue
Block a user