Chr*_*dus 10 postgresql schema postgis ruby-on-rails
我db/structure.sql用来保存我们的数据库状态,因为我们有PostGIS扩展和内置函数,使得使用schema.rb不切实际.
运行db:structure:dumprails时,有一种奇怪的行为,即在文件底部和靠近底部附近设置搜索路径.这里的问题是顶部的搜索路径不正确,导致db:schema:load失败.
我正在手动编辑它(即添加postgis到顶部搜索路径),但如果我能以某种方式通过转储任务正确设置搜索路径,那将是很好的.
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"
Run Code Online (Sandbox Code Playgroud)
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 ...
Run Code Online (Sandbox Code Playgroud)
这里的问题是,需要postgis在搜索路径中创建表(postgis毕竟它们确实使用了数据类型)
我假设第二个搜索路径集是作为设置的搜索路径的结果而添加的database.yml.
是否有可能让rails将正确的搜索路径放在文件的顶部?
我已经制作了测试项目并重复了问题中描述的操作序列 - 一切正常!我注意到规律性 - Structure.sql 包含代码:
\n\nSET search_path = public, pg_catalog;\n\nCREATE TABLE spatial_tests (\n id integer NOT NULL,\n latlon postgis.geography(Point,4326),\n geo_col postgis.geometry(Geometry,4326)\n);\nRun Code Online (Sandbox Code Playgroud)\n\n注意postgiscolumn\xe2\x80\x99s 类型的前缀。仅当 postgis 扩展存在于 postgis 模式中时,才会发生这样的代码:
postgis_test=# \\dx\n List of installed extensions\n Name | Version | Schema | Description\n---------+---------+------------+---------------------------------------------------------------------\n plpgsql | 1.0 | pg_catalog | PL/pgSQL procedural language\n postgis | 2.1.7 | postgis | PostGIS geometry, geography, and raster spatial types and functions\n(2 rows)\nRun Code Online (Sandbox Code Playgroud)\n\n并且这段代码执行得很好。在另一种情况下,当 postgis 扩展存在于公共方案中时,structural.sql 如下所示:
\n\nSET search_path = public, pg_catalog;\n\nCREATE TABLE spatial_tests (\n id integer NOT NULL,\n latlon geography(Point,4326),\n geo_col geometry(Geometry,4326)\n);\nRun Code Online (Sandbox Code Playgroud)\n\n这里,column\xe2\x80\x99s 名称中没有前缀,并且此代码在执行时会生成错误。
\n\nChris Noldus,请检查哪个方案在您进行转储的数据库中包含 postgis 扩展(您可以通过 psql 控制台中的命令进行\\dx) - 可能是 \xe2\x80\x99s 问题的原因。
这种情况可能发生在database.yml中rake db:create没有创建数据库之后postgis_schema: postgis。您可以在 activerecord-postgis-adapter文档中阅读有关此选项的详细信息。
| 归档时间: |
|
| 查看次数: |
695 次 |
| 最近记录: |