-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: environment variables interpolation #604
feat: environment variables interpolation #604
Conversation
0606177
to
21783fd
Compare
…subst` closes pressly#347 It is disabled by default to keep the existing behavior given there may be many existing scripts using `${var}` for other purposes. Can be controlled by the following annotations: - `-- +goose ENVSUBST ON` annotation enables it for all the statements following it, to the end of the file or until switched off - `-- +goose ENVSUBST OFF` annotation disables it for all the statements following it, to the end of the file or until switched on
21783fd
to
41bddf1
Compare
# Conflicts: # go.mod # go.sum
There's only one oustanding issue, CREATE OR REPLACE FUNCTION test_func()
RETURNS void AS $$
BEGIN
RAISE NOTICE '${GOOSE_ENV_NAME}';
END;
$$ LANGUAGE plpgsql; Returns: CREATE OR REPLACE FUNCTION test_func()
RETURNS void AS $
BEGIN
RAISE NOTICE 'foo';
END;
$ LANGUAGE plpgsql; Note the escaped Added a test case in 1740b96 (which is currently failing). |
|
||
case "+goose ENVSUB ON": | ||
useEnvsub = true | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mfridman I believe ability to disable further substition in a file is important, there could be huge initial migrations where one could be interested in replacing environment variables only in certain small parts of it and ignore the rest.
case "+goose ENVSUB ON": | |
useEnvsub = true | |
continue | |
case "+goose ENVSUB ON": | |
useEnvsub = true | |
continue | |
case "+goose ENVSUB OFF": | |
useEnvsubst = false | |
continue |
@mfridman This is actually expected and intented way to output a literal So one option would be to have |
Hmm, you bring up good points. I slimmed the initial PR down to see what it'd look like if we started with the simplest implementation (a single annotation). I also forked If we add the option 1 (explicit substitution)Tip This is likely what we'll recommend, wdyt @smoke -- +goose StatementBegin
CREATE OR REPLACE FUNCTION test_func()
RETURNS void AS $$
BEGIN
-- +goose ENVSUB ON
RAISE NOTICE '${GOOSE_ENV_NAME}';
-- +goose ENVSUB OFF
END;
$$ LANGUAGE plpgsql;
-- +goose StatementEnd option2 (entire file, but disable escapes as needed)Here you could have substitution enabled for the whole file, but disable the places where it should be avoided, such as PL/pgSQL . This isn't a great experience IMO. -- +goose ENVSUB ON
-- +goose Up
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION test_func()
-- +goose ENVSUB OFF
RETURNS void AS $$
-- +goose ENVSUB ON
BEGIN
RAISE NOTICE '${GOOSE_ENV_NAME}';
END;
-- +goose ENVSUB OFF
$$ LANGUAGE plpgsql;
-- +goose ENVSUB ON
-- +goose StatementEnd I presume folks will want substitution in |
I brought back the Need to sleep on this one, it does solve the problem. But it feels a bit off. Ideally, we could set a We're also not aiming to support the full range of POSIX parameter expansion formats, so maybe special casing certain parts may be an option. (This was the goal of forking TL;DR - we'll probably end up going with the
|
github.com/drone/envsubst
I am a bit biased, I am using |
Alright, let's just ship it. Based on feedback we can determine if we need to swap out the interpolate package. Another good one I found was: https://github.com/a8m/envsubst But this will all depend on how much folks need. I think the handful of expressions we support is a good starting point. |
@mfridman That is awesome! Still given it is quite common to use |
I added a section on this in the README re. explicit wrapping. Thanks for putting the original PR together. |
closes #347
It is disabled by default to keep the existing behavior given there may
be many existing scripts using
${var}
for other purposes.Can be controlled by the following annotations:
-- +goose ENVSUBST ON
annotation enables it for all the statements following it, to the end of the file or until switched off-- +goose ENVSUBST OFF
annotation disables it for all the statements following it, to the end of the file or until switched on