Skip to content

Commit c20b0ba

Browse files
authored
Merge pull request #297 from RUKAYAT-CODER/feat-env-validation
Env Validation,Database Migration, Databae performance Indexes and Soft Delete
2 parents efa661e + 45a1b41 commit c20b0ba

34 files changed

Lines changed: 768 additions & 70 deletions
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Deploy
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
services:
14+
postgres:
15+
image: postgres:15
16+
env:
17+
POSTGRES_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
18+
POSTGRES_USER: ${{ secrets.DATABASE_USER }}
19+
POSTGRES_DB: ${{ secrets.DATABASE_NAME }}
20+
options: >-
21+
--health-cmd pg_isready
22+
--health-interval 10s
23+
--health-timeout 5s
24+
--health-retries 5
25+
ports:
26+
- 5432:5432
27+
28+
steps:
29+
- uses: actions/checkout@v3
30+
31+
- name: Setup Node.js
32+
uses: actions/setup-node@v3
33+
with:
34+
node-version: '18'
35+
cache: 'npm'
36+
37+
- name: Install dependencies
38+
run: npm ci
39+
40+
- name: Build application
41+
run: npm run build
42+
43+
- name: Run database migrations
44+
run: npm run migrate
45+
env:
46+
DATABASE_HOST: localhost
47+
DATABASE_PORT: 5432
48+
DATABASE_USER: ${{ secrets.DATABASE_USER }}
49+
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
50+
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
51+
NODE_ENV: production
52+
53+
- name: Start application
54+
run: npm run start:prod
55+
env:
56+
DATABASE_HOST: localhost
57+
DATABASE_PORT: 5432
58+
DATABASE_USER: ${{ secrets.DATABASE_USER }}
59+
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }}
60+
DATABASE_NAME: ${{ secrets.DATABASE_NAME }}
61+
NODE_ENV: production
62+
# Add other required environment variables as secrets

backend/README.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,42 @@
2424

2525
## Description
2626

27-
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
27+
[SMALDA](https://github.com/RUKAYAT-CODER/SMALDA) - Secure Document Management and Ledger Anchoring system built with NestJS.
28+
29+
## Database Migrations
30+
31+
This project uses TypeORM migrations for database schema management.
32+
33+
### Migration Commands
34+
35+
```bash
36+
# Generate a new migration
37+
npm run migration:generate -- -n MigrationName
38+
39+
# Run all pending migrations
40+
npm run migration:run
41+
42+
# Revert the last migration
43+
npm run migration:revert
44+
45+
# Show migration status
46+
npm run migration:show
47+
48+
# Run migrations with CI/CD script
49+
npm run migrate
50+
```
51+
52+
### Migration Files
53+
54+
Migration files are located in `src/migrations/` and are automatically compiled to `dist/migrations/`.
55+
56+
### CI/CD Integration
57+
58+
The deployment pipeline automatically runs migrations before starting the application:
59+
60+
1. Database connection check
61+
2. Run pending migrations
62+
3. Start the application
2863

2964
## Project setup
3065

backend/ormconfig.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require('dotenv').config();
2+
3+
module.exports = {
4+
type: 'postgres',
5+
host: process.env.DATABASE_HOST,
6+
port: parseInt(process.env.DATABASE_PORT || '5432'),
7+
username: process.env.DATABASE_USER,
8+
password: process.env.DATABASE_PASSWORD,
9+
database: process.env.DATABASE_NAME,
10+
entities: ['dist/**/*.entity.js'],
11+
migrations: ['dist/migrations/*.js'],
12+
cli: {
13+
entitiesDir: 'dist',
14+
migrationsDir: 'dist/migrations',
15+
},
16+
synchronize: false,
17+
logging: false,
18+
};

backend/ormconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"type": "postgres",
3+
"host": "localhost",
4+
"port": 5432,
5+
"username": "postgres",
6+
"password": "adetomi.54",
7+
"database": "smalda",
8+
"entities": ["src/**/*.entity.ts"],
9+
"migrations": ["src/migrations/*.ts"],
10+
"cli": {
11+
"entitiesDir": "src",
12+
"migrationsDir": "src/migrations"
13+
}
14+
}

0 commit comments

Comments
 (0)