feat(projects): list + create API and creatable ProjectAutocomplete (T4)
- GET /api/projects returns the shared global list; POST /api/projects creates a project, deduped case-insensitively (F3). - Repository find-or-create trims and matches on lower(name); a unique index on lower(name) enforces the same rule at the DB (replacing the case- sensitive column unique constraint) — migration 0001. - ProjectAutocomplete: creatable autocomplete that lists projects, offers to create an unknown name inline, and selects it without reload. - Integration test (dedupe/list against Postgres) + component test.
This commit is contained in:
@@ -1,14 +1,20 @@
|
||||
// Drizzle (Postgres) schema (C8).
|
||||
// `section_id` is a plain string referencing the in-code board section ids
|
||||
// (C1) — no foreign key, because sections live in code, not the DB (ADR 0001).
|
||||
import { pgTable, uuid, text, timestamp } from 'drizzle-orm/pg-core'
|
||||
import { pgTable, uuid, text, timestamp, uniqueIndex } from 'drizzle-orm/pg-core'
|
||||
import { sql } from 'drizzle-orm'
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
export const projects = pgTable('projects', {
|
||||
id: uuid('id').primaryKey().$defaultFn(randomUUID),
|
||||
name: text('name').notNull().unique(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
})
|
||||
export const projects = pgTable(
|
||||
'projects',
|
||||
{
|
||||
id: uuid('id').primaryKey().$defaultFn(randomUUID),
|
||||
name: text('name').notNull(),
|
||||
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
|
||||
},
|
||||
// Case-insensitive uniqueness: "Acme" and "acme" are the same project (F3).
|
||||
(t) => [uniqueIndex('projects_name_lower_idx').on(sql`lower(${t.name})`)],
|
||||
)
|
||||
|
||||
export const defects = pgTable('defects', {
|
||||
id: uuid('id').primaryKey().$defaultFn(randomUUID),
|
||||
|
||||
Reference in New Issue
Block a user