Rails 与 postgresql+postgis 几何数据类型不完全兼容

发布于 2024-12-24 19:10:57 字数 194 浏览 3 评论 0原文

我使用的是 Rails 3.1,并且有带有 PostGIS geometry 数据类型的表。这些似乎与 rake db:schema:dump 或 rake db:test:clone 以及 rake test:* 任务不兼容。这些 rake 任务根本不会处理和实例化包含此数据类型的表。

有没有任何补丁或解决方案可以解决这个问题?

I'm using Rails 3.1, and I have tables with the PostGIS geometry datatype. These don't seem to be compatible with rake db:schema:dump or rake db:test:clone and the rake test:* tasks. The tables containing this datatype are simply not processed and instantiated by these rake tasks.

Is there any patch or solution for this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-12-31 19:10:57

有一个解决方案:

首先,您需要一个支持 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: template_postgis 添加到您的 config/database.yml 中,如下所示:

development:
  adapter: postgresql
  template: template_postgis
  database: postgis_db

然后 - 瞧!欢迎登机!

There is a solution:

First of all, you need a PostgreSQL template with PostGIS functions support.

Create a template database:

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

Load necessary PostGIS functions into template (I'm using Homebrew, so find the paths to your PostGIS SQL files):

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

Set database as template and grant permissions:

$ 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;

Then, add gem 'postgis_adapter' to your Gemfile and run bundle.
After that add template: template_postgis to your config/database.yml like this:

development:
  adapter: postgresql
  template: template_postgis
  database: postgis_db

And - voila! Welcome on board!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文