mirror of https://github.com/pressly/goose.git
fix(sqlparser): avoid trimming on last semicolon (#581)
parent
906a5b38bc
commit
d67f26cb2e
|
@ -258,14 +258,9 @@ func missingSemicolonError(state parserState, direction Direction, s string) err
|
|||
)
|
||||
}
|
||||
|
||||
// cleanupStatement attempts to find the last semicolon and trims
|
||||
// the remaining chars from the input string. This is useful for cleaning
|
||||
// up a statement containing trailing comments or empty lines.
|
||||
// cleanupStatement trims whitespace from the given statement.
|
||||
func cleanupStatement(input string) string {
|
||||
if n := strings.LastIndex(input, ";"); n > 0 {
|
||||
return input[:n+1]
|
||||
}
|
||||
return input
|
||||
return strings.TrimSpace(input)
|
||||
}
|
||||
|
||||
// Checks the line to see if the line has a statement-ending semicolon
|
||||
|
|
|
@ -396,6 +396,7 @@ func TestValidUp(t *testing.T) {
|
|||
{Name: "test06", StatementsCount: 5},
|
||||
{Name: "test07", StatementsCount: 1},
|
||||
{Name: "test08", StatementsCount: 6},
|
||||
{Name: "test09", StatementsCount: 1},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
path := filepath.Join("testdata", "valid-up", tc.Name)
|
||||
|
|
|
@ -29,4 +29,5 @@ BEGIN
|
|||
|
||||
EXECUTE a_output;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql';
|
||||
' LANGUAGE 'plpgsql'; -- This comment WILL BE preserved.
|
||||
-- And so will this one.
|
|
@ -31,8 +31,8 @@ BEGIN
|
|||
|
||||
EXECUTE a_output;
|
||||
END;
|
||||
' LANGUAGE 'plpgsql'; -- This comment will NOT be preserved.
|
||||
-- And neither will this one.
|
||||
' LANGUAGE 'plpgsql'; -- This comment WILL BE preserved.
|
||||
-- And so will this one.
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
|
|
|
@ -9,4 +9,7 @@ BEGIN
|
|||
-- technology was successful
|
||||
RETURN 1;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- 3 this comment WILL BE preserved
|
||||
-- 4 this comment WILL BE preserved
|
|
@ -43,8 +43,8 @@ BEGIN
|
|||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
-- 3 this comment will NOT be preserved
|
||||
-- 4 this comment will NOT be preserved
|
||||
-- 3 this comment WILL BE preserved
|
||||
-- 4 this comment WILL BE preserved
|
||||
|
||||
|
||||
-- +goose StatementEnd
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
create table t ( id int );
|
||||
update rows set value = now() -- missing semicolon. valid statement because wrapped in goose annotation, but will fail when executed.
|
|
@ -0,0 +1,8 @@
|
|||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
create table t ( id int );
|
||||
update rows set value = now() -- missing semicolon. valid statement because wrapped in goose annotation, but will fail when executed.
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE IF EXISTS t;
|
Loading…
Reference in New Issue