Skip to content

Commit 0d5fae8

Browse files
committed
Remove Flyway in favor of Knex migrations
1 parent 673f61c commit 0d5fae8

File tree

7 files changed

+47
-101
lines changed

7 files changed

+47
-101
lines changed

.env.example

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
1-
FLYWAY_USER=your_db_user
2-
FLYWAY_PASSWORD=your_db_password
3-
FLYWAY_DB=your_db_name
4-
# Using port 5433 because 5432 is already in use by the local PostgreSQL server
5-
# localhost because an SSH tunnel is used to connect to the RDS instance
6-
FLYWAY_URL=jdbc:postgresql://localhost:5433/your_db_name
71
PORT=3000
82
DATABASE_URL=postgres://your_db_user:your_db_password@localhost:5432/your_db_name

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,4 @@ Thumbs.db
6363

6464
!.env.example
6565

66-
# Flyway
67-
flyway.conf
68-
6966
notes.md

README.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
# InterviewPrep
22

3-
This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 18.2.4.
3+
This project grew out of wanting to prepare for an interview for a job that would have focused on Angular. As I had been using React exclusively for several months, I needed to refresh my Angular skills. Then I began to add more things to make up for my focus on AWS Amplify. The result is in some ways the opposite of what I have in my previous videos:
4+
5+
* Angular instead of React/NextJS
6+
* Angular Material instead of AWS Amplify's UI library. (I do, however, use Tailwind CSS in both.)
7+
* Postgres instead of DynamoDB (Sql vs NoSQL)
8+
* REST (using a NodeJS/Express backend) vs GraphQL (using Amplify and AppSync)
9+
* This project has nothing in regard to authentication (yet), while the Amplify project implemented authentication right at the beginning.
10+
11+
Also, in the Amplify project I haven't yet implemented any automated testing but in this project I have unit and integration tests. I set up a GitHub Workflow with GitHub Actions to run the tests when there is a push to or a pull request on specified branches.
12+
13+
This project is Dockerized, and I developed it in a devcontainer.
14+
15+
You'll see some Terraform files in the project but I'll get to that in the next video.
16+
17+
## Devcontainer
18+
19+
I'm using the [Node.js & TypeScript (typescript-node)](https://github.com/devcontainers/templates/tree/main/src/typescript-node) devcontainer. The features I added are
20+
21+
* [sshpass](https://github.com/hspaans/devcontainer-features/tree/master/src/sshpass): installs the GitHub CLI
22+
* [Angular CLI](https://github.com/devcontainers-extra/features/tree/main/src/angular-cli)
23+
* [docker-outside-of-docker](https://github.com/devcontainers/features/tree/main/src/docker-outside-of-docker): "Re-use the host docker socket, adding the Docker CLI to a container. Feature invokes a script to enable using a forwarded Docker socket within a container to run Docker commands."
24+
* [Prettier](https://github.com/devcontainers-community/npm-features/tree/main/src/prettier)
25+
* [AWS CLI](https://github.com/devcontainers/features/tree/main/src/aws-cli)
26+
* [Terraform](https://github.com/devcontainers/features/tree/main/src/terraform)
27+
* [PostgreSQL Client](https://github.com/robbert229/devcontainer-features/blob/main/src/postgresql-client/README.md)
28+
29+
In devcontainer.json you'll see that I'm specifying a network. That's so the devcontainer and the Docker services can communicate with one another. For instance, from a shell within the devcontainer I can connect to the service running the Postgres test database.
30+
31+
I also have some mounts so that
32+
33+
* git can authenticate with GitHub using the SSH agent on my laptop (the host machine)
34+
* devcontainer can communicate with the host's Docker daemon
35+
* the AWS credentials and configuration are available within the devcontainer.
36+
437

5-
## Development
638

739
### Frontend
840

@@ -50,22 +82,18 @@ To get more help on the Angular CLI use `ng help` or go check out the [Angular C
5082
`ssh -f -i <PATH TO KEY-PAIR PEM> -L 5433:interviewprepdbinstance.c92egeoumrf1.us-east-1.rds.amazonaws.com:5432 ec2-user@107.22.66.121 -N`
5183
- To keep SSH tunnel alive: `ssh -f -i <PATH TO KEY-PAIR PEM> -L 5433:interviewprepdbinstance.c92egeoumrf1.us-east-1.rds.amazonaws.com:5432 ec2-user@107.22.66.121 -N -o ServerAliveInterval=60 -o ServerAliveCountMax=3`
5284

53-
## Flyway and Migrations
85+
## Migrations
5486

5587
DB credentials and URLs are in `.env.local` and `.env.development`. Set the environment to be used: `export NODE_ENV=local` or `export NODE_ENV=production`.
5688

57-
The migrations are run (if necessary) after the db container comes up.
58-
5989
Maybe obsolete:
6090

61-
You need an SSH tunnel to be able to run the Flyway migrations on the db in AWS. Check for a tunnel by using `ps aux | grep ssh`. It will look something like
91+
You need an SSH tunnel to be able to run the migrations on the db in AWS. Check for a tunnel by using `ps aux | grep ssh`. It will look something like
6292

6393
```
6494
davidsilva 69319 0.0 0.0 410379280 1904 ?? Ss 12:34PM 0:00.01 ssh -f -i /Users/davidsilva/Downloads/OnyxKeyPair.pem -L 5433:interviewprepdbinstance.c92egeoumrf1.us-east-1.rds.amazonaws.com:5432 ec2-user@107.22.66.121 -N
6595
```
6696

67-
To run migrations, run `./run-flyway.sh`.
68-
6997
# SSH into Bastion Host
7098

7199
The security group only allows SSH connections from my VPN IP address.
@@ -201,3 +229,14 @@ Could run in the background or in separate shell to have HTML reports loaded (an
201229

202230
Everything except the tests will run because frontend is dependent upon backend, which is dependent upon db.
203231
`docker-compose --env-file .env.local up --build frontend`
232+
233+
# Database
234+
235+
With `interview-prep-db-1` up and running, you can access the db via psql using...
236+
237+
`docker exec -it interview-prep-db-1 psql -U interviewprep_admin -d interviewprepdbinstance`
238+
239+
## Run Migrations
240+
241+
`docker-compose --env-file .env.local up migrate`
242+

flyway.conf.template

Lines changed: 0 additions & 19 deletions
This file was deleted.

migrations/V1__Create_products_table.sql

Lines changed: 0 additions & 24 deletions
This file was deleted.

migrations/V2__Create_users_table.sql

Lines changed: 0 additions & 24 deletions
This file was deleted.

run-flyway.sh

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)