Skip to content

Commit cc7097a

Browse files
committed
feat(db): add unique constraint for branches per project
1 parent 6a76a87 commit cc7097a

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/core/db/schema.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { sql } from "drizzle-orm";
2-
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
2+
import { integer, sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
33
import { INTENT_STATUS } from "../constants";
44

55
const nowMs = sql`(strftime('%s','now') * 1000)`;
@@ -13,16 +13,20 @@ export const projects = sqliteTable("projects", {
1313
.default(nowMs),
1414
});
1515

16-
export const branches = sqliteTable("branches", {
17-
id: text("id").primaryKey(),
18-
projectId: text("project_id")
19-
.notNull()
20-
.references(() => projects.id),
21-
name: text("name").notNull(),
22-
createdAt: integer("created_at", { mode: "timestamp_ms" })
23-
.notNull()
24-
.default(nowMs),
25-
});
16+
export const branches = sqliteTable(
17+
"branches",
18+
{
19+
id: text("id").primaryKey(),
20+
projectId: text("project_id")
21+
.notNull()
22+
.references(() => projects.id),
23+
name: text("name").notNull(),
24+
createdAt: integer("created_at", { mode: "timestamp_ms" })
25+
.notNull()
26+
.default(nowMs),
27+
},
28+
(table) => [unique("unq_branch_project").on(table.name, table.projectId)],
29+
);
2630

2731
export const intents = sqliteTable("intents", {
2832
id: integer("id").primaryKey({ autoIncrement: true }),

0 commit comments

Comments
 (0)