Skip to content

Commit 714527b

Browse files
committed
added migration and create option for spec
Signed-off-by: RAWx18 <rawx18.dev@gmail.com>
1 parent 9ee1d0d commit 714527b

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

backend/src/api/devtel/specs/specCreate.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default async (req, res) => {
1919
}
2020

2121
const spec = await req.database.devtelSpecDocuments.create({
22+
tenantId: req.currentTenant.id,
2223
projectId,
2324
authorId: req.currentUser.id,
2425
title,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
-- Create DevTel Spec Documents table
2+
CREATE TABLE IF NOT EXISTS "devtelSpecDocuments" (
3+
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
4+
"tenantId" UUID NOT NULL,
5+
"projectId" UUID NOT NULL REFERENCES "devtelProjects"("id") ON DELETE CASCADE,
6+
"authorId" UUID NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
7+
"title" VARCHAR(500) NOT NULL,
8+
"content" JSONB DEFAULT '{}',
9+
"status" VARCHAR(20) DEFAULT 'draft',
10+
"createdById" UUID REFERENCES "users"("id"),
11+
"updatedById" UUID REFERENCES "users"("id"),
12+
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
13+
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
14+
"deletedAt" TIMESTAMP WITH TIME ZONE
15+
);
16+
17+
CREATE INDEX IF NOT EXISTS "devtelSpecDocuments_tenantId" ON "devtelSpecDocuments"("tenantId");
18+
CREATE INDEX IF NOT EXISTS "devtelSpecDocuments_projectId" ON "devtelSpecDocuments"("projectId");
19+
CREATE INDEX IF NOT EXISTS "devtelSpecDocuments_authorId" ON "devtelSpecDocuments"("authorId");
20+
CREATE INDEX IF NOT EXISTS "devtelSpecDocuments_status" ON "devtelSpecDocuments"("status");
21+
CREATE INDEX IF NOT EXISTS "devtelSpecDocuments_deletedAt" ON "devtelSpecDocuments"("deletedAt");
22+
23+
-- Create DevTel Spec Versions table
24+
CREATE TABLE IF NOT EXISTS "devtelSpecVersions" (
25+
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
26+
"specId" UUID NOT NULL REFERENCES "devtelSpecDocuments"("id") ON DELETE CASCADE,
27+
"authorId" UUID NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
28+
"content" JSONB NOT NULL,
29+
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
30+
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
31+
);
32+
33+
CREATE INDEX IF NOT EXISTS "devtelSpecVersions_specId" ON "devtelSpecVersions"("specId");
34+
CREATE INDEX IF NOT EXISTS "devtelSpecVersions_authorId" ON "devtelSpecVersions"("authorId");
35+
36+
-- Create DevTel Spec Comments table
37+
CREATE TABLE IF NOT EXISTS "devtelSpecComments" (
38+
"id" UUID PRIMARY KEY DEFAULT gen_random_uuid(),
39+
"specId" UUID NOT NULL REFERENCES "devtelSpecDocuments"("id") ON DELETE CASCADE,
40+
"authorId" UUID NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
41+
"content" TEXT NOT NULL,
42+
"createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
43+
"updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW(),
44+
"deletedAt" TIMESTAMP WITH TIME ZONE
45+
);
46+
47+
CREATE INDEX IF NOT EXISTS "devtelSpecComments_specId" ON "devtelSpecComments"("specId");
48+
CREATE INDEX IF NOT EXISTS "devtelSpecComments_authorId" ON "devtelSpecComments"("authorId");

backend/src/database/models/devtel.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ export default (sequelize) => {
271271
defaultValue: DataTypes.UUIDV4,
272272
primaryKey: true,
273273
},
274+
tenantId: {
275+
type: DataTypes.UUID,
276+
allowNull: false,
277+
},
274278
projectId: {
275279
type: DataTypes.UUID,
276280
allowNull: false,

0 commit comments

Comments
 (0)