From dd1fc11118f196a9089e66d6f8e26032721aefa5 Mon Sep 17 00:00:00 2001 From: Vojtech Vitek Date: Tue, 5 Mar 2019 16:20:45 -0500 Subject: [PATCH] Add plpgsql syntax unit test #91 --- sql_parser_test.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/sql_parser_test.go b/sql_parser_test.go index 886426a..d7adafa 100644 --- a/sql_parser_test.go +++ b/sql_parser_test.go @@ -47,6 +47,7 @@ func TestSplitStatements(t *testing.T) { {sql: functxt, up: 2, down: 2}, {sql: mysqlChangeDelimiter, up: 4, down: 0}, {sql: copyFromStdin, up: 1, down: 0}, + {sql: plpgsqlSyntax, up: 2, down: 2}, } for i, test := range tt { @@ -289,3 +290,27 @@ COPY public.django_content_type (id, app_label, model) FROM stdin; \. -- +goose StatementEnd ` + +var plpgsqlSyntax = ` +-- +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 +-- +goose StatementBegin +CREATE TRIGGER update_properties_updated_at BEFORE UPDATE ON properties FOR EACH ROW EXECUTE PROCEDURE update_updated_at_column(); +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +DROP TRIGGER update_properties_updated_at +-- +goose StatementEnd +-- +goose StatementBegin +DROP FUNCTION update_updated_at_column() +-- +goose StatementEnd +`