rtp-atw / nimble-interview

Nimble Repository
https://nimble-interview.vercel.app
MIT License
0 stars 0 forks source link

[Question] Running DB migrations #17

Closed olivierobert closed 8 months ago

olivierobert commented 8 months ago

Issue

I cannot use the application yet since the DB migrations have not been run yet 😅

Screenshot 2566-12-06 at 08 32 10

The concern is that the README is rather unclear on how to run the migrations:

https://github.com/rtp-atw/nimble-interview/blob/adc3255cb11f2b27182cb909e52f6919396b73db/backend/README.md?plain=1#L13-L18

Where should I run these? Is there any local package that must be installed? I am currently used the Dockerised version of the application.

I also wonder why not using the auto DB migration of Gorm: https://gorm.io/docs/migration.html#Auto-Migration?

rtp-atw commented 8 months ago

Apologies for the unclear documentation and the delayed response.

I have written two versions of the readme files: one is located within the backend scope, and the other is for the outer scope.

I'm using golang-migrate/migrate to manage the version control of the database schema, as opposed to manually migrating through GORM's Auto Migration feature.

Therefore, you can follow these steps to perform database migration in outer scope same level as docker-compose.yaml.

  1. Install migrate cmd from brew install golang-migrate.
  2. Set env $MIGRATE_POSTGRESQL_URL as "postgres://postgres:postgres@localhost:5432/nimble?sslmode=disable"
  3. Run docker-compose
  4. Run cmd below to perform database migration. (Reference in the readme.md in the outer scope)
    migrate -database $MIGRATE_POSTGRESQL_URL -path backend/adapters/db/migrations up

Lastly, I attempted to run the migration command from Docker, but it did not work as expected, and I couldn't find the solution in time.

olivierobert commented 8 months ago

The README is missing this critical piece of information:

Install migrate cmd from brew install golang-migrate.

[!Note] Since is it a dependency, it needs to be listed as a pre-requisite in the installation instructions.

Once installed, it worked without any issue:

image

And I can access the application:

image