shared zod types and drizzle schema

This commit is contained in:
Oliver Bryan
2025-12-13 21:36:32 +00:00
parent b2284b1b30
commit 9d381ca4ff
13 changed files with 1269 additions and 1987 deletions

View File

@@ -1,6 +1,6 @@
import { eq, sql, and } from "drizzle-orm";
import { db } from "../client";
import { Issue } from "../schema";
import { Issue } from "@issue/shared";
export async function createIssue(projectId: number, title: string, description: string) {
// prevents two issues with the same unique number

View File

@@ -1,6 +1,6 @@
import { eq } from "drizzle-orm";
import { db } from "../client";
import { Issue, Project, User } from "../schema";
import { Issue, Project, User } from "@issue/shared";
export async function createProject(blob: string, name: string, ownerId: number) {
const [project] = await db

View File

@@ -1,6 +1,6 @@
import { eq } from "drizzle-orm";
import { db } from "../client";
import { User } from "../schema";
import { User } from "@issue/shared";
export async function createUser(name: string, username: string) {
const [user] = await db.insert(User).values({ name, username }).returning();

View File

@@ -1,36 +0,0 @@
import { integer, pgTable, uniqueIndex, varchar } from "drizzle-orm/pg-core";
export const User = pgTable("User", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
name: varchar({ length: 256 }).notNull(),
username: varchar({ length: 32 }).notNull().unique(),
});
export const Project = pgTable("Project", {
id: integer().primaryKey().generatedAlwaysAsIdentity(),
blob: varchar({ length: 4 }).notNull(),
name: varchar({ length: 256 }).notNull(),
ownerId: integer()
.notNull()
.references(() => User.id),
});
export const Issue = pgTable(
"Issue",
{
id: integer().primaryKey().generatedAlwaysAsIdentity(),
projectId: integer()
.notNull()
.references(() => Project.id),
number: integer("number").notNull(),
title: varchar({ length: 256 }).notNull(),
description: varchar({ length: 2048 }).notNull(),
},
(t) => [
// ensures unique numbers per project
// you can have Issue 1 in PROJ and Issue 1 in TEST, but not two Issue 1s in PROJ
uniqueIndex("unique_project_issue_number").on(t.projectId, t.number),
],
);

View File

@@ -1,5 +1,5 @@
import { db, testDB } from "./db/client";
import { User } from "./db/schema";
import { User } from "@issue/shared";
import { routes } from "./routes";
import { createDemoData } from "./utils";