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
47 changes: 40 additions & 7 deletions .github/workflows/backend-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,63 @@ on:

jobs:
build:
name: Build and Test
name: Build and Test (${{ matrix.database }})
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./apps/backend

strategy:
matrix:
database: [sqlite, postgres]

services:
postgres:
image: postgres:15
env:
POSTGRES_USER: vaultix
POSTGRES_PASSWORD: vaultix_password
POSTGRES_DB: vaultix_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: apps/backend/package-lock.json

- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 8

- name: Install dependencies
run: npm ci
run: pnpm install

- name: Lint
run: npm run lint
run: pnpm run lint
if: matrix.database == 'sqlite'

- name: Build
run: npm run build
run: pnpm run build
if: matrix.database == 'sqlite'

- name: Set environment variables for Postgres
if: matrix.database == 'postgres'
run: |
echo "DATABASE_DRIVER=postgres" >> $GITHUB_ENV
echo "DATABASE_URL=postgresql://vaultix:vaultix_password@localhost:5432/vaultix_test" >> $GITHUB_ENV

- name: Run Migrations
run: pnpm run migration:run

- name: Test
run: npm run test
run: pnpm run test
26 changes: 19 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Before you begin, ensure you have the following installed:
Edit `apps/backend/.env` with your configuration:
```env
# Database Configuration
DATABASE_PATH=./data/vaultix.db # SQLite path (or use DATABASE_URL for PostgreSQL)
DATABASE_DRIVER=sqlite
DATABASE_PATH=./data/vaultix.db # SQLite path (For PostgreSQL, set DATABASE_DRIVER=postgres and use DATABASE_URL)

# JWT Configuration
JWT_SECRET=your-super-secret-jwt-key-change-in-production
Expand Down Expand Up @@ -223,9 +224,17 @@ taskkill /PID <PID> /F
```

**Database connection errors**:
- Ensure PostgreSQL is running: `pg_ctl status` or check Docker container
- Ensure PostgreSQL is running: `pg_ctl status` or check Docker container (if using PostgreSQL)
- Verify `DATABASE_DRIVER` is correctly set to `sqlite` or `postgres`
- Verify `DATABASE_URL` or `DATABASE_PATH` in `.env`
- Run migrations: `cd apps/backend && pnpm typeorm migration:run`
- Run migrations: `cd apps/backend && pnpm run migration:run`

**Migrating SQLite to PostgreSQL**:
If you wish to migrate an existing SQLite database to PostgreSQL, use the provided migration script:
```bash
cd apps/backend
pnpm run db:migrate:postgres
```

**TypeScript/Linting errors**:
```bash
Expand Down Expand Up @@ -265,12 +274,15 @@ cargo build --target wasm32v1-none --release
```

### Environment Setup
1. Set up PostgreSQL: Create `vaultix_db` and run migrations:
```
npx prisma migrate dev --name init
1. Set up PostgreSQL (Recommended for Production) or SQLite (Default for Local Development):
For PostgreSQL, create `vaultix_db` and run migrations:
```bash
cd apps/backend
pnpm run migration:run
```
2. Copy `.env.example` to `.env` and configure:
```
```env
DATABASE_DRIVER="postgres" # or "sqlite"
DATABASE_URL="postgresql://username:password@localhost:5432/vaultix_db"
JWT_SECRET="your-super-secret-jwt-key"
STELLAR_NETWORK="testnet" # "mainnet" for production
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Database Configuration
# Supported drivers: sqlite, postgres
DATABASE_DRIVER=sqlite

# SQLite (Local Development)
DATABASE_PATH=./data/vaultix.db

# PostgreSQL (Production)
# DATABASE_DRIVER=postgres
# DATABASE_URL=postgresql://user:password@localhost:5432/vaultix

# JWT Configuration (Required at startup, minimum 32 characters long)
JWT_SECRET=your-32-character-minimum-super-secret-key-here
JWT_EXPIRES_IN=15m
Expand Down
Binary file modified apps/backend/data/vaultix.db
Binary file not shown.
4 changes: 3 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"seed:admin": "ts-node src/scripts/admin-seed.ts",
"typeorm": "ts-node -r tsconfig-paths/register ./node_modules/typeorm/cli.js",
"db:migrate:postgres": "ts-node src/scripts/migrate-sqlite-to-postgres.ts",
"typeorm": "typeorm-ts-node-commonjs",
"migration:generate": "npm run typeorm -- migration:generate -d src/data-source.ts",
"migration:run": "npm run typeorm -- migration:run -d src/data-source.ts",
"migration:revert": "npm run typeorm -- migration:revert -d src/data-source.ts",
Expand Down Expand Up @@ -56,6 +57,7 @@
"nodemailer": "^8.0.3",
"passport": "^0.7.0",
"passport-jwt": "^4.0.1",
"pg": "^8.23.0",
"pino-http": "^11.0.0",
"pino-pretty": "^13.1.3",
"reflect-metadata": "^0.2.2",
Expand Down
Loading
Loading