Merge pull request #171 from nesv/158-fix-sql-parser

Fix SQL parser regression
This commit is contained in:
Vojtech Vitek 2019-05-03 16:56:32 -04:00 committed by GitHub
commit c35094e758
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {
@ -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();
`