diff --git a/sql_parser.go b/sql_parser.go index 27d146669..a3f002fc9 100644 --- a/sql_parser.go +++ b/sql_parser.go @@ -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 { diff --git a/sql_parser_test.go b/sql_parser_test.go index 594596b2b..facc55d2b 100644 --- a/sql_parser_test.go +++ b/sql_parser_test.go @@ -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(); +`