Skip to content

Commit 9a82341

Browse files
committed
feat: configure Railway deployment
1 parent 3080255 commit 9a82341

9 files changed

Lines changed: 38 additions & 4856 deletions

File tree

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ Pushes to `main` automatically deploy after CI passes.
2727
- Click "New Project" → "Deploy from GitHub repo"
2828
- Select the `daimyo` repository
2929

30-
2. **Set Environment Variables**
30+
2. **Add PostgreSQL Database**
31+
- In Railway, click "New" → "Database" → "Add PostgreSQL"
32+
- Railway will automatically set `DATABASE_URL` for your service
33+
34+
3. **Set Environment Variables**
3135
- In Railway, go to your service → Variables
3236
- Add the following (see `backend/.env.example` for reference):
3337
```
@@ -40,7 +44,6 @@ Pushes to `main` automatically deploy after CI passes.
4044
SENPAI_ROLE_ID=<role id>
4145
SENSEI_ROLE_ID=<role id>
4246
OHAYO_CHANNEL_ID=<channel id>
43-
DATABASE_PATH=/data/daimyo.db
4447
4548
# Reputation thresholds
4649
DECAY_WINDOW_DAYS=360
@@ -55,11 +58,6 @@ Pushes to `main` automatically deploy after CI passes.
5558
TYPEFULLY_API_KEY=<your typefully key>
5659
```
5760
58-
3. **Create Volume for Database**
59-
- In Railway, click your service → Settings → Volumes
60-
- Add a volume with mount path `/data`
61-
- This persists the SQLite database across deployments
62-
6361
4. **(Optional) GitHub Branch Protection**
6462
- Go to GitHub repo → Settings → Branches
6563
- Add rule for `main` branch

backend/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Implements a reputation system where users earn roles (Kōhai → Senpai → Sen
1717

1818
- **TypeScript** - Type-safe development
1919
- **Discord.js v14** - Discord bot framework
20-
- **SQLite (better-sqlite3)** - Local database with WAL mode
20+
- **PostgreSQL (postgres.js)** - Production database
2121
- **node-cron** - Scheduled decay checks
2222

2323
## Setup
@@ -84,8 +84,8 @@ KOHAI_ROLE_ID=your_kohai_role_id
8484
SENPAI_ROLE_ID=your_senpai_role_id
8585
SENSEI_ROLE_ID=your_sensei_role_id
8686
87-
# Database
88-
DATABASE_PATH=./daimyo.db
87+
# Database (PostgreSQL connection URL)
88+
DATABASE_URL=postgresql://user:password@host:5432/daimyo
8989
9090
# Reputation Thresholds (optional, defaults shown)
9191
DECAY_WINDOW_DAYS=360
@@ -122,7 +122,7 @@ pnpm start
122122

123123
The bot will:
124124

125-
- Initialize the SQLite database
125+
- Connect to PostgreSQL database
126126
- Connect to Discord
127127
- Fetch all guild members
128128
- Start listening for reactions
@@ -194,7 +194,7 @@ backend/
194194
│ │ ├── guildMemberAdd.ts
195195
│ │ └── messageReactionAdd.ts
196196
│ ├── services/ # Core business logic
197-
│ │ ├── database.ts # SQLite queries
197+
│ │ ├── database.ts # PostgreSQL queries
198198
│ │ ├── roleManager.ts # Discord role management
199199
│ │ ├── reputation.ts # Promotion logic
200200
│ │ └── decay.ts # Demotion logic
@@ -376,13 +376,13 @@ const reaction = createMockReaction('msg-1', 'author-1', 'dojo');
376376

377377
#### Test Database
378378

379-
Tests use in-memory SQLite databases for fast, isolated testing:
379+
Tests use PGlite (in-memory PostgreSQL) for fast, isolated testing:
380380

381381
```typescript
382382
import { createTestDatabase, insertTestReaction } from '__tests__/mocks/database';
383383

384-
const db = createTestDatabase();
385-
insertTestReaction(db, 'msg-1', 'author-1', 'reactor-1', Role.Senpai);
384+
const db = await createTestDatabase();
385+
await insertTestReaction(db, 'msg-1', 'author-1', 'reactor-1', Role.Senpai);
386386
```
387387

388388
### Manual Testing Checklist

backend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"typecheck": "tsc --noEmit -p tsconfig.build.json",
1111
"start": "node dist/index.js",
1212
"deploy-commands": "tsx src/deploy-commands.ts",
13+
"test-ohayo": "tsx src/test-ohayo.ts",
1314
"lint": "eslint .",
1415
"lint:fix": "eslint . --fix",
1516
"format": "prettier --write \"**/*.{ts,js,json,md}\"",
@@ -38,7 +39,6 @@
3839
"author": "",
3940
"license": "MIT",
4041
"dependencies": {
41-
"better-sqlite3": "^12.5.0",
4242
"discord.js": "^14.25.1",
4343
"dotenv": "^17.2.3",
4444
"node-cron": "^4.2.1",
@@ -48,7 +48,6 @@
4848
},
4949
"devDependencies": {
5050
"@electric-sql/pglite": "^0.3.15",
51-
"@types/better-sqlite3": "^7.6.13",
5251
"@types/jest": "^30.0.0",
5352
"@types/node": "^25.0.3",
5453
"@types/node-cron": "^3.0.11",

0 commit comments

Comments
 (0)