Giter VIP home page Giter VIP logo

Comments (6)

dhui avatar dhui commented on May 18, 2024

Are you able to reproduce the problem in psql?

Looking at Run() in the postgres DB driver, the raw SQL statements are run from the migration file w/o any transforms, so it's unlikely that the problem is due to migrate

from migrate.

kamal-github avatar kamal-github commented on May 18, 2024

I had to place the whole function in a single line and parse it by \n. Please add some kind of annotation like goose does for solving the same problem.

from migrate.

dhui avatar dhui commented on May 18, 2024

To be clear, migrate migration files do not contain annotations, are not interpreted by migrate, and are passed unmodified to the DB driver, which should be executing the migration with the DB.

I'm not sure what your problem was, but it seems like your migration file had some type of error in it or was malformed.

I didn't have any issues running this migration set (up and down) with migrate 3.2.0 and postgres 10:
Up:

create table "test_function" (
  name VARCHAR(126)
);

create or replace function update_tsvector() returns trigger
as $update_tsvector$
begin
  UPDATE test_function SET tsv = setweight(to_tsvector(name), 'A');
  RETURN NULL;
end;
$update_tsvector$ LANGUAGE plpgsql;


CREATE TRIGGER update_tsvector
AFTER INSERT OR update of name ON test_function
FOR EACH ROW EXECUTE PROCEDURE update_tsvector();

Down:

DROP TRIGGER IF EXISTS "update_tsvector" ON "test_function";

DROP FUNCTION IF EXISTS "update_tsvector";

DROP TABLE IF EXISTS "test_function";

If there's a bug or usability issue w/ migrate, we should address that, but that doesn't seem to be the case. Please correct me if I'm mistaken.

from migrate.

dhui avatar dhui commented on May 18, 2024

Closing due to inactivity. Please reopen if there's an issue with migrate itself.

from migrate.

andream16 avatar andream16 commented on May 18, 2024

@dhui I'm seeing error pq: unterminated dollar-quoted string at or near "$$ when running this migration:

CREATE OR REPLACE FUNCTION some_func(param text)
RETURNS integer AS $$
BEGIN
    INSERT into my_table (my_column) VALUES (param) ON CONFLICT DO NOTHING;
    RETURN (SELECT id FROM my_table where my_column = param);
END;
$$ LANGUAGE plpgsql;

The driver is postgres and I'm instantiating a new migrate client like this:

migrate.New("file://pathToMigrations", "postgres://user:password@hostname:port")

i'm using postgres 9.5 and this version of migrate:

github.com/golang-migrate/migrate/v4 v4.14.2-0.20210203071828-a185b9e78f19

Any ideas?

from migrate.

dhui avatar dhui commented on May 18, 2024

@andream16 are you able to reproduce the issue using postgres directly? Or using pq directly?
With multi-statements disable, you can see that the migration file contents is passed unmodified to postgres via lib/pq

from migrate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.