added playground and userroute
This commit is contained in:
@@ -2,14 +2,16 @@ import {
|
||||
sqliteTable,
|
||||
text,
|
||||
integer,
|
||||
uniqueIndex,
|
||||
primaryKey,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
import { relations } from "drizzle-orm";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
|
||||
//----------------User
|
||||
export const user = sqliteTable("users", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
firstName: text("firstName").notNull(),
|
||||
lastName: text("lastName").notNull(),
|
||||
title: text("title").notNull(),
|
||||
phone: text("phone").unique().notNull(),
|
||||
email: text("email"),
|
||||
job: text("job").notNull(),
|
||||
@@ -19,6 +21,9 @@ export const user = sqliteTable("users", {
|
||||
group: integer("group_id")
|
||||
.references(() => group.id)
|
||||
.notNull(),
|
||||
zone: integer("zone_id")
|
||||
.notNull()
|
||||
.references(() => zone.id),
|
||||
});
|
||||
|
||||
export const userRelation = relations(user, ({ many, one }) => ({
|
||||
@@ -27,6 +32,10 @@ export const userRelation = relations(user, ({ many, one }) => ({
|
||||
fields: [user.group],
|
||||
references: [group.id],
|
||||
}),
|
||||
zone: one(zone, {
|
||||
fields: [user.zone],
|
||||
references: [zone.id],
|
||||
}),
|
||||
}));
|
||||
|
||||
//----------------Group
|
||||
@@ -47,13 +56,19 @@ export const opinion = sqliteTable("opinions", {
|
||||
});
|
||||
|
||||
//----------------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 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"),
|
||||
},
|
||||
(t) => ({
|
||||
pk: primaryKey({ columns: [t.userId, t.opinionId] }),
|
||||
})
|
||||
);
|
||||
|
||||
export const userOpinionRelation = relations(userOpinion, ({ one }) => ({
|
||||
user: one(user, {
|
||||
@@ -84,5 +99,14 @@ export const province = sqliteTable("provinces", {
|
||||
});
|
||||
|
||||
export const provinceRelation = relations(province, ({ many }) => ({
|
||||
province: many(zone),
|
||||
zones: many(zone),
|
||||
}));
|
||||
|
||||
//----------------PhoneToken
|
||||
export const phoneToken = sqliteTable("phone_tokens", {
|
||||
phone: text("phone").primaryKey(),
|
||||
token: text("token").notNull(),
|
||||
createdOn: integer("created_on", { mode: "timestamp" }).default(
|
||||
sql`CURRENT_TIMESTAMP`
|
||||
),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user