Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ WORKDIR /todo_api
COPY --from=builder /todo_api ./
RUN yarn install --production=true
EXPOSE 8080
ENTRYPOINT ["yarn", "serve"]
ENTRYPOINT ["yarn"]
30 changes: 9 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,23 @@ Make sure you have [Docker](https://www.docker.com/) installed

### Setting up

**Commands**

To install the database management, run:

```bash
docker-compose up -d
```

To create database, run:

```bash
docker exec -it todo psql -U postgres -c "create database todo"
```

**.env file**

1. Create the `.env` file
2. Copy and parse the `connection information` below:

```bash
DB_USER=postgres
DB_HOST=localhost
DB_DATABASE=todo
DB_PORT=54320
POSTGRES_USER=docker
POSTGRES_PASSWORD=docker
POSTGRES_HOST=localhost
POSTGRES_DB=todo
POSTGRES_PORT=54320
```

## Create tables

Open and run the `database/sql/database.sql` by postgres tools (i.e. [pgAdmin](https://www.pgadmin.org/))
**database**
```bash
docker-compose up -d
```

## Seeding data

Expand Down
2 changes: 0 additions & 2 deletions database/sql/database.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
create database todo;

create table todo_list
(
id serial primary key not null,
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ services:
db:
image: "postgres:11"
container_name: "todo"
env_file:
- ./.env
ports:
- "54320:5432"
volumes:
- todo:/var/lib/postgresql/data
volumes:
todo:
- ./database/sql/database.sql:/docker-entrypoint-initdb.d/database.sql
10 changes: 5 additions & 5 deletions scripts/seed/db/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ require('dotenv').config();

function connect() {
return new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT,
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/db/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ require('dotenv').config();

export function connect() {
return new Pool({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
password: process.env.DB_PASSWORD,
port: process.env.DB_PORT,
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
port: process.env.POSTGRES_PORT,
});
}