Repository navigation
Conversation
Between -- +goose ENVSUB ON and OFF, goose replaces ${NAME} with environment variables. The analysis now reads each braced expansion as the named parameter $NAME, padded to the same length, so it no longer causes syntax errors. Fixes that would edit inside an expansion are dropped, and the formatter leaves statements with expansions alone. Named parameters after more keywords that name objects, like REFERENCES and INTO, are now identifiers.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
goose's
-- +goose ENVSUB ONreplaces${NAME}with environment variables before it runs the SQL (parser.go, using interpolate). We parsed the expansions as written, so every statement with one was a syntax error and got no linting:Behaviour
Real substitution doesn't fit a linter: the environment of the editor or CI isn't the one goose runs in, and a missing variable becomes an empty string. Instead, between
ENVSUB ONandENVSUB OFF, each braced expansion (${NAME},${NAME:-default},${NAME:?}, … with nested braces) is read as the named parameter$NAME, padded with spaces to the same length:Named parameters already get the psql-variable treatment (
:name,@name,$name): they are identifiers where an object name is expected and value parameters elsewhere, and statements with identifier parameters aren't typechecked. The unbraced$NAMEthat interpolate also expands is a named parameter already. The escapes\$,$$and\\are left as written, as is$(. The text keeps its length, so diagnostics, fixes and LSP positions need no offset mapping.Documentkeeps the content as written (get_document_content), and splits and parses the substituted text.fix_file. Without that,constraintMissingNotValidputNOT VALIDinside${PARENT}, once per pass, because the end of the constraint was the padded placeholder. There's a test for that. Fixes elsewhere in the statement still apply, and the expansion stays as written.sectionMarkers: "goose". The annotation is specific enough.To avoid new syntax errors, I had to extend the identifier heuristic of the named-parameter conversion in
pgls_lexer: parameters afterINTO,JOIN,ON,UPDATE,TRUNCATE,REFERENCES,EXISTS,VIEW,SEQUENCE,EXTENSION,FUNCTIONandTRIGGERare now identifiers.references ${PARENT}was converted to a value parameter, which doesn't parse. This also helps psql variables, e.g.insert into :items.Tests
Unit tests for the substitution (ON/OFF regions, nested defaults, escapes, offsets, no annotation). Workspace tests: no syntax error between ON and OFF but one after OFF, with the rules still running;
fix_filekeeping${SCHEMA}while fixing around it; no fix inside an expansion; the formatter leaving the statement unchanged. A lexer test covers the new identifier contexts. The migrations guide describes the behaviour.Not covered
$$inside anENVSUBregion becomes$for goose, so dollar-quoted bodies break there in goose itself. We still read them as dollar quotes.