加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails-3 – Rails与postgresql postgis几何数据类型不完

发布时间:2020-12-17 02:30:49 所属栏目:百科 来源:网络整理
导读:我正在使用Rails 3.1,并且我有PostGIS几何数据类型的表.这些似乎与rake db:schema:dump或rake db:test:clone和rake test:* tasks不兼容.包含此数据类型的表不会被这些rake任务处理和实例化. 这有补丁或解决方案吗? 解决方法 有一个解决方案: 首先,您
我正在使用Rails 3.1,并且我有PostGIS几何数据类型的表.这些似乎与rake db:schema:dump或rake db:test:clone和rake test:* tasks不兼容.包含此数据类型的表不会被这些rake任务处理和实例化.

这有补丁或解决方案吗?

解决方法

有一个解决方案:

首先,您需要一个支持PostGIS功能的PostgreSQL模板.

创建模板数据库:

$psql -U postgres
> CREATE DATABASE template_postgis WITH TEMPLATE=template1 ENCODING='UTF8';
> c template_postgis;
> CREATE LANGUAGE plpgsql;

将必要的PostGIS功能加载到模板中(我使用的是Homebrew,因此找到PostGIS SQL文件的路径):

$psql -f /usr/local/share/postgis/postgis.sql template_postgis
$psql -f /usr/local/share/postgis/spatial_ref_sys.sql template_postgis

将数据库设置为模板并授予权限:

$psql -U postgres template_postgis
> UPDATE pg_database SET datistemplate = TRUE WHERE datname = 'template_postgis';
> GRANT ALL ON geometry_columns TO PUBLIC;
> GRANT ALL ON spatial_ref_sys TO PUBLIC;

然后,将gem’postgis_adapter’添加到您的Gemfile并运行bundle.
之后添加模板:template_postgis到你的config / database.yml,如下所示:

development:
  adapter: postgresql
  template: template_postgis
  database: postgis_db

而且 – 瞧!欢迎登机!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读