mirror of
https://github.com/hex248/sprint.git
synced 2026-02-07 18:23:03 +00:00
shared zod types and drizzle schema
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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),
|
||||
],
|
||||
);
|
||||
@@ -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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user