mirror of
https://github.com/pressly/goose.git
synced 2025-05-31 11:42:04 +00:00
Merge pull request #171 from nesv/158-fix-sql-parser
Fix SQL parser regression
This commit is contained in:
commit
c35094e758
@ -174,10 +174,12 @@ func parseSQLMigration(r io.Reader, direction bool) (stmts []string, useTx bool,
|
|||||||
stmts = append(stmts, buf.String())
|
stmts = append(stmts, buf.String())
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
verboseInfo("StateMachine: store Up statement")
|
verboseInfo("StateMachine: store Up statement")
|
||||||
|
stateMachine.Set(gooseUp)
|
||||||
case gooseStatementEndDown:
|
case gooseStatementEndDown:
|
||||||
stmts = append(stmts, buf.String())
|
stmts = append(stmts, buf.String())
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
verboseInfo("StateMachine: store Down statement")
|
verboseInfo("StateMachine: store Down statement")
|
||||||
|
stateMachine.Set(gooseDown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := scanner.Err(); err != nil {
|
if err := scanner.Err(); err != nil {
|
||||||
|
@ -51,6 +51,7 @@ func TestSplitStatements(t *testing.T) {
|
|||||||
{sql: mysqlChangeDelimiter, up: 4, down: 0},
|
{sql: mysqlChangeDelimiter, up: 4, down: 0},
|
||||||
{sql: copyFromStdin, up: 1, down: 0},
|
{sql: copyFromStdin, up: 1, down: 0},
|
||||||
{sql: plpgsqlSyntax, up: 2, down: 2},
|
{sql: plpgsqlSyntax, up: 2, down: 2},
|
||||||
|
{sql: plpgsqlSyntaxMixedStatements, up: 2, down: 2},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tt {
|
for i, test := range tt {
|
||||||
@ -319,3 +320,25 @@ DROP TRIGGER update_properties_updated_at
|
|||||||
DROP FUNCTION update_updated_at_column()
|
DROP FUNCTION update_updated_at_column()
|
||||||
-- +goose StatementEnd
|
-- +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();
|
||||||
|
`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user