Skip to content

Add GOOSE_MIGRATION_DIR env variable#337

Merged
mfridman merged 1 commit intomasterfrom
dir-env-variable
Apr 28, 2022
Merged

Add GOOSE_MIGRATION_DIR env variable#337
mfridman merged 1 commit intomasterfrom
dir-env-variable

Conversation

@mfridman
Copy link
Copy Markdown
Collaborator

Add an env variable to allow setting the migration directory: GOOSE_MIGRATION_DIR

Order of precedence:

  1. Flags
  2. Environment variables
  3. Default values (if available)

Fix #329

@VojtechVitek
Copy link
Copy Markdown
Collaborator

This looks good.

But shouldn't we rather explore go:embed instead of reaching for .sql files to a file system?

@mfridman
Copy link
Copy Markdown
Collaborator Author

mfridman commented Apr 26, 2022

But shouldn't we rather explore go:embed instead of reaching for .sql files to a file system?

The env variables are only relevant in main.go, where we compile the binaries and distribute them. In this form there is no go:embed.

But for folks that use goose as a library these env variables don't apply since they specify the embedded directory:

//go:embed migrations/*.sql
var embedMigrations embed.FS

...

goose.SetBaseFS(embedMigrations)
goose.Up(db, "migrations")

Does that sound about right?

@VojtechVitek
Copy link
Copy Markdown
Collaborator

Right! Yep all good, Mike :)

@mfridman mfridman merged commit 1311a0e into master Apr 28, 2022
@mfridman mfridman deleted the dir-env-variable branch April 28, 2022 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: Add environment variable support for migrations directory.

2 participants