Skip to content

Commit 23b4b3e

Browse files
feat : add an Encrypted Message Storage (#372)
* feat : add an Encrypted Message Storage * fix: resolve merge conflict * fix: resolve merge conflict * fix: resolve merge conflict * fix: resolve merge conflict * fix: resolve merge conflict * fix: resolve merge conflict
1 parent 57304f2 commit 23b4b3e

19 files changed

+40
-21
lines changed

backend/fix_migrations.bat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
@echo off
2+
REM Fix all migrations to include uuid-ossp extension
3+
4+
echo Fixing migrations to include uuid-ossp extension...
5+
6+
REM List of migrations that need the fix (excluding init)
7+
set migrations=20260221151200_add_notifications_and_action_logs.sql 20260224153500_add_nonces.sql 20260226000000_add_lending_events.sql 20260226140000_create_user_2fa.sql 20260324120000_add_emergency_access_tracking.sql 20260324170000_add_emergency_contacts.sql 20260324173000_add_emergency_access_audit_logs.sql 20260324180000_add_emergency_access_risk_alerts.sql 20260325100000_add_pools_for_stress_testing.sql 20260325103000_add_governance_tables.sql 20260325190000_add_emergency_access_sessions.sql
8+
9+
for %%f in (%migrations%) do (
10+
echo Checking migrations\%%f
11+
findstr /C:"CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\"" migrations\%%f >nul
12+
if errorlevel 1 (
13+
echo Adding extension to %%f
14+
echo -- Ensure UUID extension is available> temp.sql
15+
echo CREATE EXTENSION IF NOT EXISTS "uuid-ossp";>> temp.sql
16+
echo.>> temp.sql
17+
type migrations\%%f >> temp.sql
18+
move /Y temp.sql migrations\%%f >nul
19+
) else (
20+
echo %%f already has extension
21+
)
22+
)
23+
24+
echo Done!
Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
-- Migration: Add plans and plan_logs tables
2-
3-
CREATE TABLE plans (
4-
id SERIAL PRIMARY KEY,
5-
user_id INTEGER NOT NULL,
6-
amount NUMERIC(20, 6) NOT NULL,
7-
fee NUMERIC(20, 6) NOT NULL,
8-
net_amount NUMERIC(20, 6) NOT NULL,
9-
status VARCHAR(32) NOT NULL,
10-
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
11-
updated_at TIMESTAMP NOT NULL DEFAULT NOW()
12-
);
1+
-- Migration: Add plan_logs table
2+
-- NOTE:
3+
-- The plans table is already created in the initial migration.
4+
-- This migration should only add the dependent plan_logs table.
135

146
CREATE TABLE plan_logs (
157
id SERIAL PRIMARY KEY,
16-
plan_id INTEGER NOT NULL REFERENCES plans(id),
8+
plan_id UUID NOT NULL REFERENCES plans(id) ON DELETE CASCADE,
179
action VARCHAR(64) NOT NULL,
18-
performed_by INTEGER NOT NULL,
19-
timestamp TIMESTAMP NOT NULL DEFAULT NOW()
10+
performed_by UUID NOT NULL,
11+
timestamp TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT NOW()
2012
);
13+
14+
CREATE INDEX idx_plan_logs_plan_id ON plan_logs(plan_id);
15+
CREATE INDEX idx_plan_logs_performed_by ON plan_logs(performed_by);

backend/migrations/20260223000000_add_claim_plan_unique_constraint.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
-- Add unique constraint on plan_id in claims table to prevent duplicate claims
22
-- This ensures only one claim per plan, preventing race condition vulnerabilities
33

4-
-- First, remove any existing duplicate claims (keep the first one)
4+
-- First, remove any existing duplicate claims (keep the first one by created_at)
55
DELETE FROM claims
66
WHERE id NOT IN (
7-
SELECT MIN(id)
7+
SELECT DISTINCT ON (plan_id) id
88
FROM claims
9-
GROUP BY plan_id
9+
ORDER BY plan_id, created_at ASC
1010
);
1111

1212
-- Drop the existing unique constraint on (plan_id, beneficiary_email)
-585 Bytes
Binary file not shown.
-2.34 KB
Binary file not shown.
-1.3 KB
Binary file not shown.
Binary file not shown.
-889 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)