Skip to content

Commit

Permalink
Merge pull request #1 from ardentink/add_postgres_and_type-orm
Browse files Browse the repository at this point in the history
Add postgres and type orm
  • Loading branch information
dansteren committed Dec 19, 2020
2 parents 37b98e4 + 2c1b7f1 commit 448d22c
Show file tree
Hide file tree
Showing 15 changed files with 1,775 additions and 96 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
node_modules

# Secrets
.env
*.local.env
*.env
!example.local.env

# VS Code
.vscode/*
Expand Down
19 changes: 19 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@
"showReuseMessage": true,
"clear": true
}
},
{
"label": "Start Postgres Container",
"type": "shell",
"command": "docker-compose",
"args": [
"up",
"-d",
"db"
],
"problemMatcher": [],
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
}
}
],
"inputs": [
Expand Down
6 changes: 6 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Formulae
brew "direnv"
brew "node"

# Casks
cask "docker"
cask "tableplus"
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- [Postgres](https://www.postgresql.org/)
- [TypeORM](https://typeorm.io/#/)

[unreleased]: https://github.com/ardentink/adr-api/compare/v0.1.0...HEAD
[0.1.0]: https://github.com/ardentink/adr-api/releases/tag/v0.1.0
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ ADR Api is a node.js backend for storing/managing Architectural Decision Records
- typescript
- type-graphql
- apollo-sever

## System Requirements

- MacOS
- Node >= 10

## Getting Started

1. Clone the repo
2. Install system dependencies: `brew bundle`
3. Create env file: `cp example.local.env .env`
4. Start up docker desktop: `open -a Docker`
5. Start the dev DB container: `docker-compose up -D db`
6. Run migrations: `npx ts-node ./node_modules/.bin/typeorm migration:run`
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3.9'
services:
db:
container_name: adr_db
image: postgres
restart: always
env_file: .env
networks:
- inter-net
ports:
- '5432:5432'
volumes:
- 'data:/var/lib/postgresql/data'

volumes:
data:

networks:
inter-net:
driver: bridge
12 changes: 12 additions & 0 deletions example.local.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DB_HOST=localhost
DB_PORT=5432
DB_NAME=adr
DB_USERNAME=app
DB_PASSWORD=
POSTGRES_DB=$DB_NAME
POSTGRES_USER=$DB_USERNAME
POSTGRES_PASSWORD=$DB_PASSWORD
TYPEORM_SYNCHRONIZE=false
TYPEORM_LOGGING=false
APP_PORT=8080
NODE_ENV=development
31 changes: 31 additions & 0 deletions ormconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
switch (process.env.NODE_ENV) {
case 'production':
case 'staging':
folder = 'dist'
extension = 'js'
break
case 'development':
default:
folder = 'src'
extension = 'ts'
break
}

module.exports = {
type: 'postgres',
host: process.env.DB_HOST,
port: process.env.DB_PORT,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
synchronize: false,
logging: false,
entities: [`${folder}/entity/**/*.${extension}`],
migrations: [`${folder}/migration/**/*.${extension}`],
subscribers: [`${folder}/subscriber/**/*.${extension}`],
cli: {
entitiesDir: `${folder}/entity`,
migrationsDir: `${folder}/migration`,
subscribersDir: `${folder}/subscriber`
}
}

0 comments on commit 448d22c

Please sign in to comment.