Skip to content

Commit

Permalink
feat: Dev database with backup and restore scripts (#141)
Browse files Browse the repository at this point in the history
* feat: Create backup script

* fix: Explicity call bash for non-unix environments

* feat: Alternative approach using docker

* fix: Handle issue with env files

* feat: Local dev db, backup and restore scripts, via Docker

* docs: Add mermaid diagram to readme

* fix: Remove pnpm lockfile

* fix: dev script

* chore: Setup .gitattributes to handle line endings
  • Loading branch information
DafyddLlyr authored Nov 15, 2024
1 parent 3fc5af3 commit 3b184d8
Show file tree
Hide file tree
Showing 10 changed files with 296 additions and 212 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Ensure shell scripts use LF (Unix) line endings, not CRLF (Windows)
*.sh text eol=lf
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@ next.config.mjs
next-env.d.ts

# IDE
.vscode
.vscode

# backups
backups/*.sql
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,53 @@ You can check out [the Next.js GitHub repository](https://github.com/vercel/next
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.


## Architecture

```mermaid
flowchart LR
classDef todo stroke-dasharray: 5 5

subgraph "fairhold-data"
S1[(Source 1)] <---> Script
S2[(Source 2)] <---> Script
S3[(Source 3)] <---> Script
end

subgraph "DB tools"
LD[(Local disk)] --> UpdateData
LD <--> Backup
LD --> Restore
end

subgraph "Local development"
NextLocal[Next.js App]
PrismaLocal[Prisma]
LocalDB[(Database)]
PrismaLocal <--> NextLocal
LocalDB <--> PrismaLocal
end

subgraph "CI/CD"
GitHub["GitHub actions"]
end


subgraph "Production (Vercel)"
NextProd[Next.js App]
PrismaProd[Prisma]
ProdDB[(Database)]
PrismaProd <--> NextProd
ProdDB <--> PrismaProd
end

Script -- Writes to --> LD

Restore -- .env.local --> LocalDB
Backup <-- .env.production --> ProdDB
UpdateData:::todo -- .env.production --> ProdDB

PrismaLocal -- "Migration files" --> GitHub
GitHub -- "Merge to main" --> ProdDB
```
Empty file added backups/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.8'
services:
postgres:
image: postgres:17
env_file:
- .env.local
environment:
POSTGRES_DB: ${POSTGRES_DATABASE}
ports:
- "5400:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

dbtools:
image: postgres:17
volumes:
- ./backups:/backups
- ./scripts:/scripts
environment:
POSTGRES_URL: ${POSTGRES_URL}
POSTGRES_DATABASE: ${POSTGRES_DATABASE}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
depends_on:
postgres:
condition: service_healthy
profiles:
- tools

volumes:
postgres_data:
18 changes: 0 additions & 18 deletions load-env-and-prisma.js

This file was deleted.

Loading

0 comments on commit 3b184d8

Please sign in to comment.