Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/db-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- 'prisma/schema.prisma'
- 'prisma.config.ts'
- 'prisma/migrations/**'

permissions:
Expand Down
11 changes: 11 additions & 0 deletions prisma.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@

import { defineConfig } from "prisma/config";

const databaseUrl =
process.env.DATABASE_URL ??
"postgresql://test_user:test_password@localhost:5432/test_db";

export default defineConfig({
schema: "prisma/schema.prisma",
datasource: {
url: databaseUrl,
import { defineConfig } from '@prisma/config';

export default defineConfig({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- CreateTable
CREATE TABLE "organizations" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,
"slug" TEXT NOT NULL,
"ownerId" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "organizations_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "organization_members" (
"id" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"userId" TEXT NOT NULL,
"role" TEXT NOT NULL DEFAULT 'member',
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "organization_members_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "organizations_slug_key" ON "organizations"("slug");

-- CreateIndex
CREATE INDEX "organizations_ownerId_idx" ON "organizations"("ownerId");

-- CreateIndex
CREATE INDEX "organization_members_userId_idx" ON "organization_members"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "organization_members_organizationId_userId_key" ON "organization_members"("organizationId", "userId");

-- AddForeignKey
ALTER TABLE "organizations" ADD CONSTRAINT "organizations_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "organizations"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
75 changes: 54 additions & 21 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,58 @@ datasource db {
}

model User {
id String @id @default(cuid())
email String @unique
createdAt DateTime @default(now())
alerts Alert[]
watchlist Watchlist[]
id String @id @default(cuid())
email String @unique
createdAt DateTime @default(now())
alerts Alert[]
watchlist Watchlist[]
notificationPreferences NotificationPreference[]
auditLogs AuditLog[]
ownedOrganizations Organization[] @relation("OrganizationOwner")
organizationMemberships OrganizationMember[]

@@map("users")
}

model Organization {
id String @id @default(cuid())
name String
slug String @unique
ownerId String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

owner User @relation("OrganizationOwner", fields: [ownerId], references: [id])
members OrganizationMember[]

@@index([ownerId])
@@map("organizations")
}

model OrganizationMember {
id String @id @default(cuid())
organizationId String
userId String
role String @default("member")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
user User @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([organizationId, userId])
@@index([userId])
@@map("organization_members")
}

model Alert {
id String @id @default(cuid())
id String @id @default(cuid())
userId String
message String
severity String
status String @default("open")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
status String @default("open")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

acknowledgedAt DateTime?
acknowledgedBy String?
Expand Down Expand Up @@ -86,8 +119,8 @@ model Proposal {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

votes Vote[]
events GovernanceEvent[]
votes Vote[]
events GovernanceEvent[]

@@map("proposals")
}
Expand All @@ -96,25 +129,25 @@ model Vote {
id String @id @default(cuid())
proposalId String
voter String
choice String // "yes", "no", "abstain"
choice String // "yes", "no", "abstain"
weight String
createdAt DateTime @default(now())

proposal Proposal @relation(fields: [proposalId], references: [id])
proposal Proposal @relation(fields: [proposalId], references: [id])

@@map("votes")
}

model GovernanceEvent {
id String @id @default(cuid())
eventType String // "proposal_created", "vote_cast"
eventType String // "proposal_created", "vote_cast"
proposalId String?
voter String?
transactionHash String @unique
metadata Json?
createdAt DateTime @default(now())

proposal Proposal? @relation(fields: [proposalId], references: [id])
proposal Proposal? @relation(fields: [proposalId], references: [id])

@@map("governance_events")
}
Expand All @@ -124,17 +157,17 @@ model GovernanceEvent {
// ---------------------------------------------------------------------------

model InvestigationNote {
id String @id @default(cuid())
id String @id @default(cuid())
caseId String
authorId String
authorName String
title String?
content String
tags String[]
deleted Boolean @default(false)
deleted Boolean @default(false)
deletedAt DateTime?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

auditEntries NoteAuditLog[]

Expand All @@ -145,7 +178,7 @@ model InvestigationNote {
model NoteAuditLog {
id String @id @default(cuid())
noteId String
action String // "created" | "updated" | "deleted"
action String // "created" | "updated" | "deleted"
actorId String
actorName String
previousValues Json?
Expand All @@ -156,4 +189,4 @@ model NoteAuditLog {

@@index([noteId])
@@map("note_audit_logs")
}
}
Loading