add unique constraint
This commit is contained in:
@@ -3,6 +3,7 @@ import {
|
||||
text,
|
||||
integer,
|
||||
primaryKey,
|
||||
unique,
|
||||
} from "drizzle-orm/sqlite-core";
|
||||
import { relations, sql } from "drizzle-orm";
|
||||
|
||||
@@ -41,7 +42,7 @@ export const userRelation = relations(user, ({ many, one }) => ({
|
||||
//----------------Group
|
||||
export const group = sqliteTable("groups", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
name: text("name").unique().notNull(),
|
||||
});
|
||||
|
||||
export const groupRelation = relations(group, ({ many }) => ({
|
||||
@@ -51,7 +52,7 @@ export const groupRelation = relations(group, ({ many }) => ({
|
||||
//----------------Opinion
|
||||
export const opinion = sqliteTable("opinions", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
name: text("name").unique().notNull(),
|
||||
type: text("type", { enum: ["3Choice", "4Choice"] })
|
||||
.default("3Choice")
|
||||
.notNull(),
|
||||
@@ -84,13 +85,17 @@ export const userOpinionRelation = relations(userOpinion, ({ one }) => ({
|
||||
}));
|
||||
|
||||
//----------------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 zone = sqliteTable(
|
||||
"zones",
|
||||
{
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
province: integer("province_id")
|
||||
.notNull()
|
||||
.references(() => province.id),
|
||||
},
|
||||
(t) => ({ unique_name_province: unique().on(t.name, t.province) })
|
||||
);
|
||||
export const zoneRelation = relations(zone, ({ one }) => ({
|
||||
province: one(province, {
|
||||
fields: [zone.province],
|
||||
@@ -101,7 +106,7 @@ export const zoneRelation = relations(zone, ({ one }) => ({
|
||||
//----------------Province
|
||||
export const province = sqliteTable("provinces", {
|
||||
id: integer("id", { mode: "number" }).primaryKey({ autoIncrement: true }),
|
||||
name: text("name").notNull(),
|
||||
name: text("name").unique().notNull(),
|
||||
});
|
||||
|
||||
export const provinceRelation = relations(province, ({ many }) => ({
|
||||
|
||||
Reference in New Issue
Block a user