I am using db/structure.sql
to preserve our DB State as we have PostGIS
extensions and built in functions that make using schema.rb
impractical.
When running db:structure:dump
rails has the odd behaviour of setting search paths near the top AND near the bottom of the file. The problem here is that the search path at the top is incorrect, causing db:schema:load
to fail miserably.
I am editing it manually at the moment (i.e. adding postgis
to the top search path), but it would be nice if I could somehow get the search path set correctly by the dump task.
database.yml
development: &dev
adapter: postgis
database: myapp_dev
host: localhost
encoding: utf8
template: template0 # Required for UTF8 encoding
postgis_extension: true
schema_search_path: "public,postgis"
db/structure.sql
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
... Table / Sequence / Index creation happens here ...
--
-- PostgreSQL database dump complete
--
SET search_path TO public,postgis;
... Migrations inserted here ...
The problem here, is that the tables need postgis
in the search path to be created (they do use postgis
data types after all)
I presume the second search path set is added as a result of the search paths set in database.yml
.
Is it possible to get rails to put the correct search path at the top of the file?