Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:ruby schema dump not respecting search paths (postgres) #116

Open
HoneyryderChuck opened this issue Jun 2, 2016 · 2 comments
Open

:ruby schema dump not respecting search paths (postgres) #116

HoneyryderChuck opened this issue Jun 2, 2016 · 2 comments

Comments

@HoneyryderChuck
Copy link

Whenever the schema is dumped, I have these lines in the end:

...
Sequel.migration do
     change do
         self << "SET search_path TO project_development"
....

I am using the same database for "development" and "test", and these define 2 different search paths. I set them in the database.yml (or DATABASE_URL, doesn't matter), that means, the db connection from Sequel knows beforehand in which search path to apply the migrations. Problem is, when this is part of the schema, I can't perform:

> RAILS_ENV=test bundle exec rake db:schema:load

Although the previous operations are going to be evaluated in the desired test search path, as soon as the migration line way above is executed, all subsequent operations will be evaluated in the development search path, thereby breaking everything. As you might know, everything coming after are schema_migration entries for every migration ran, and this already exists in the development search path, as the schema was dumped from there(!).

So, I think setting the search path should be out of the schema dump.

@HoneyryderChuck
Copy link
Author

Would also like to add, it seems also "buggy" in the sql structure dump. See

def schema_information_inserts(migrator, sql_dump)
migrator.ds.map do |hash|
insert = migrator.ds.insert_sql(hash)
sql_dump ? "#{insert};" : "self << #{insert.inspect}"
end
end
. I don't know exactly where it happens, but the dump contains:

CREATE SCHEMA proj_dev;

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


SET search_path = proj_dev, pg_catalog;

I don't know if this comes from sequel or is injected by sequel-rails, but I'd say that, the same way that the dump doesn't try to create the database and the db user/role, it also shouldn't try to create the schemas, which is all part of expected information to connect.

@HoneyryderChuck
Copy link
Author

I've just confirmed, structure:dump issue is from sequel-rails. I think it uses the psql cli tool to generate it, and search_path info comes with it. No easy way to circumvent this with this strategy, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant