Skip to content

Commit

Permalink
Merge pull request #171 from nesv/158-fix-sql-parser
Browse files Browse the repository at this point in the history
Fix SQL parser regression
  • Loading branch information
VojtechVitek authored May 3, 2019
2 parents a0b467f + a479445 commit c35094e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sql_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ func parseSQLMigration(r io.Reader, direction bool) (stmts []string, useTx bool,
stmts = append(stmts, buf.String())
buf.Reset()
verboseInfo("StateMachine: store Up statement")
stateMachine.Set(gooseUp)
case gooseStatementEndDown:
stmts = append(stmts, buf.String())
buf.Reset()
verboseInfo("StateMachine: store Down statement")
stateMachine.Set(gooseDown)
}
}
if err := scanner.Err(); err != nil {
Expand Down
23 changes: 23 additions & 0 deletions sql_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestSplitStatements(t *testing.T) {
{sql: mysqlChangeDelimiter, up: 4, down: 0},
{sql: copyFromStdin, up: 1, down: 0},
{sql: plpgsqlSyntax, up: 2, down: 2},
{sql: plpgsqlSyntaxMixedStatements, up: 2, down: 2},
}

for i, test := range tt {
Expand Down Expand Up @@ -319,3 +320,25 @@ DROP TRIGGER update_properties_updated_at
DROP FUNCTION update_updated_at_column()
-- +goose StatementEnd
`

var plpgsqlSyntaxMixedStatements = `
-- +goose Up
-- +goose StatementBegin
CREATE OR REPLACE FUNCTION update_updated_at_column()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = now();
RETURN NEW;
END;
$$ language 'plpgsql';
-- +goose StatementEnd
CREATE TRIGGER update_properties_updated_at
BEFORE UPDATE
ON properties
FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column();
-- +goose Down
DROP TRIGGER update_properties_updated_at;
DROP FUNCTION update_updated_at_column();
`

0 comments on commit c35094e

Please sign in to comment.