Skip to content

Commit b798570

Browse files
wiktoriavhCopilot
andauthored
feat: add database for moderation (#4)
* chore: add plan for database * feat: introduce prisma * docs: implement SQLite database with Prisma for moderation actions tracking * feat: add moderation tables and update schema for user actions tracking * feat: implement database connection and graceful shutdown in bot * feat: add analytics and operations modules for user and moderation action management * test: add comprehensive database tests * refactor: improve variable naming for clarity in analytics and database tests * test: enhance database action counting tests to verify accurate totals after action creation and error removal * refactor: update Prisma schema to introduce new roles and action types, and streamline action status definitions * feat: add User and Action models to Prisma schema, replacing ModerationAction and updating relationships * chore: remove unused analytics and operations modules along with associated tests * fix: correct spelling of 'DISRESPECTFUL' in ActionReason enum in Prisma schema * chore: remove outdated database implementation plan and related files * chore: update docker-compose and Dockerfile to use named volumes and add migration service * chore: update datasource URL in Prisma configuration to point to moderation database * chore: remove unused script.ts file and related database connection logic * Update prisma/schema.prisma Co-authored-by: Copilot <[email protected]> * chore: add new Prisma scripts for database migration, validation, and formatting; update dependencies * chore: upgrade Prisma dependencies to version 7.0.0 and update related lockfile entries * chore: update Prisma schema to add VOICE_MODERATOR role, rename DISRESPECTFUL to DISRUPTIVE, and clean up model relationships --------- Co-authored-by: Copilot <[email protected]>
1 parent 65374af commit b798570

File tree

13 files changed

+1284
-4
lines changed

13 files changed

+1284
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,5 @@ tmp/
166166
.env.production.local
167167

168168
# esbuild metafile
169-
meta.json
169+
meta.json
170+
/generated/prisma

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ FROM deps-dev AS build
2727

2828
COPY . .
2929

30+
# Generate Prisma client
31+
RUN npx prisma generate
32+
3033
RUN pnpm run build:ci
3134

3235
# Production stage - Minimal runtime image
@@ -39,7 +42,10 @@ COPY --from=deps /app/node_modules ./node_modules
3942

4043
# Copy built application
4144
COPY --from=build /app/dist ./dist
45+
COPY --from=build /app/generated ./generated
46+
COPY --from=build /app/prisma ./prisma
4247
COPY package.json ./
48+
COPY prisma.config.ts ./
4349

4450
# Create data directory and set permissions for node user
4551
RUN mkdir -p /app/data && chown -R node:node /app/data
@@ -56,6 +62,9 @@ ENV NODE_ENV=development
5662

5763
COPY . .
5864

65+
# Generate Prisma client
66+
RUN npx prisma generate
67+
5968
# Create data directory and set permissions for node user
6069
RUN mkdir -p /app/data && chown -R node:node /app/data
6170

docker-compose.yml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ services:
1414
environment:
1515
- NODE_ENV=production
1616
volumes:
17-
- ./logs:/app/logs
18-
- ./data:/app/data
17+
- prod_logs:/app/logs
18+
- prod_data:/app/data # Named volume - persists outside repo
1919

2020
discord-bot-dev:
2121
build:
@@ -34,4 +34,25 @@ services:
3434
- ./logs:/app/logs
3535
- ./data:/app/data
3636
ports:
37-
- "9229:9229" # For debugging
37+
- "9229:9229" # For debugging
38+
39+
# Run database migrations manually when ready
40+
migrate:
41+
build:
42+
context: .
43+
dockerfile: Dockerfile
44+
target: production
45+
container_name: moderation-tool-migrate
46+
profiles: ["tools"]
47+
env_file:
48+
- .env.local
49+
volumes:
50+
- prod_data:/app/data # Use same named volume as production
51+
command: npx prisma migrate deploy
52+
53+
# Named volumes - persist outside the repo directory
54+
volumes:
55+
prod_data:
56+
name: discord-moderation-data
57+
prod_logs:
58+
name: discord-moderation-logs

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,26 @@
1414
"format": "biome format --write .",
1515
"check": "biome check .",
1616
"check:fix": "biome check --write .",
17+
"db:migrate": "prisma migrate dev",
18+
"db:validate": "prisma validate",
19+
"db:format": "prisma format",
1720
"prepare": "husky",
1821
"pre-commit": "lint-staged",
1922
"typecheck": "tsc --noEmit"
2023
},
2124
"license": "MIT",
2225
"packageManager": "[email protected]",
2326
"dependencies": {
27+
"@prisma/adapter-better-sqlite3": "^7.0.0",
28+
"@prisma/client": "^7.0.0",
2429
"discord.js": "^14.22.1"
2530
},
2631
"devDependencies": {
2732
"@biomejs/biome": "^2.2.4",
2833
"@types/node": "^24.5.2",
2934
"husky": "^9.1.7",
3035
"lint-staged": "^16.2.1",
36+
"prisma": "^7.0.0",
3137
"tsx": "^4.20.6",
3238
"typescript": "^5.9.2"
3339
},

0 commit comments

Comments
 (0)