yogthos / migratus

MIGRATE ALL THE THINGS!
643 stars 93 forks source link

Unterminated dollar quote #160

Closed ccann closed 5 years ago

ccann commented 5 years ago

Hello!

I recently copied a migration from one project to another and was surprised when it wouldn't run, so I compared my dependencies:

Project A:

[org.postgresql/postgresql "9.4.1212"]
[migratus "1.0.6"]

Project B (migration doesn't work):

[org.postgresql/postgresql "42.2.5"]
[migratus "1.1.9"]

And here's the migration itself:

CREATE OR REPLACE FUNCTION set_updated_at()
RETURNS TRIGGER AS $$
BEGIN
    NEW.updated_at = now();
    RETURN NEW;
END;
$$ language 'plpgsql';

CREATE TRIGGER set_notes_updated_time
BEFORE UPDATE ON notes
FOR EACH ROW
EXECUTE PROCEDURE set_updated_at();

I swapped some deps around and noticed that this migration works with postgres 42.5.5 + migratus 1.0.6 -> migratus 1.0.9 I see the error:

ERROR migratus.migration.sql - Unterminated dollar quote started at position 63 in SQL CREATE OR REPLACE FUNCTION set_updated_at()

starting with migratus 1.1.2 and up through 1.1.9. The other versions 1.1.0 + 1.1.1 wouldn't run my rollbacks for a seemingly separate issue.

Overriding the org.clojure/java.jdbc version and changing it around didn't seem to interact with the issue. Hopefully i'm not doing something silly, let me know if I can provide more info.

I'm using v2.1.4 of the mac postgres app, but i'm seeing the same error in my CircleCI build environment too.

yogthos commented 5 years ago

IT looks like the problem might be caused by this pr that ends up splitting statements by ;. I'm thinking that I could either make that functionality opt-in or change it to another delimiter. @fl00r would you have any preference here?

fl00r commented 5 years ago

that's why they invented lisps and lists :)

no preferences, but maybe you could change default separator and give us a possibility to change it via cli

yogthos commented 5 years ago

OK, I pushed out 1.2.0 with a fix. The commands will no longer be split by default, however you can now provide the :command-separator key in the config that should point to a string that will be used to split the statements.

yogthos commented 5 years ago

I'll close this one for now, and if anything new comes up we can look at it.