pressly / goose

A database migration tool. Supports SQL migrations and Go functions.
http://pressly.github.io/goose/
Other
7.16k stars 523 forks source link

But with the migrations dir environment variable #839

Closed kevinmarquesp closed 1 month ago

kevinmarquesp commented 1 month ago

Steps to reproduce the bug:

  1. Set this environment variable with GOOSE_MIGRATION_DIR=./infra/postgres/migrations, or with set -U GOOSE_MIGRATION_DIR ./infra/postgres/migrations in my case, I'm using the Fish shell.
  2. Echo this variable out, just to confirm that it was saved correctly.
  3. Create try to create a table with goose create profile_and_credentials sql

Then the file is created in the current directory. For some reason, it isn't getting the variables from the environment. Is that normal?

I'm using the version 3.22.1, the latest release.

mfridman commented 1 month ago

Nope, that's not expected. The GOOSE_MIGRATION_DIR env variable should be a drop-in replacement for for the -dir flag.

I use zsh and can't seem to reproduce it (at least locally on my machine). Maybe you could try the following?

goose --version
goose version: v3.22.1

# from the root of this repository
export GOOSE_MIGRATION_DIR=testdata/migrations
goose create some_file sql
2024/10/19 08:39:24 Created new file: testdata/migrations/20241019123924_some_file.sql

tree testdata/migrations/
testdata/migrations/
├── 00001_users_table.sql
├── 00002_posts_table.sql
├── 00003_comments_table.sql
├── 00004_insert_data.sql
├── 00005_posts_view.sql
└── 20241019123924_some_file.sql

1 directory, 6 files

Is it possible it's something to do with the fish shell?

kevinmarquesp commented 1 month ago

Oh, I'm sorry. I forgot to actually export the variable outside my shell. I was literally typing GOOSE_MIGRATION_DIR=./migrations and hitting enter.

Fish actually accept this syntax, like export KEY=value, but in the Fish way is to set a variable with the export flag as set -x KEY value.

Thanks for actually responding, and sorry for the silly mistake. haha

mfridman commented 1 month ago

No worries, it happens to us all :)