From 2a30a64180cf40a2d9c38a1baf1c644724f4b547 Mon Sep 17 00:00:00 2001 From: Frederick Hoyles Date: Sat, 3 Feb 2024 17:04:59 +0100 Subject: [PATCH 1/2] Duplicate notes of running enable_extension migration to README --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index dfd006bf..4bf7a1b2 100644 --- a/README.md +++ b/README.md @@ -248,7 +248,25 @@ Once you have set up your database config, run: rake db:create ``` -to create your development database. The adapter will add the PostGIS extension to your database. +to create your development database. + +Then, create a migration to add the PostGIS extension to your database. +```rake +rails g migration AddPostgisExtensionToDatabase +``` +The migration should look something like this: +```ruby +class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0] + def change + enable_extension 'postgis' + end +end +``` + +Then run the migration: +```rake +rails db:migrate +``` Once you have installed the adapter, edit your `config/database.yml` as described above. From a06b54e8dc019143c6469e192a5446334afd37fe Mon Sep 17 00:00:00 2001 From: Frederick Hoyles Date: Sat, 3 Feb 2024 17:26:42 +0100 Subject: [PATCH 2/2] Combine "Creating a Spatial Rails App" and "Upgrading an Existing Database" The two sections shared most of their steps so keeping them separate just made duplication. --- README.md | 62 ++++++++++++++++--------------------------------------- 1 file changed, 18 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 4bf7a1b2..3dbbdea3 100644 --- a/README.md +++ b/README.md @@ -222,66 +222,39 @@ development: This adapter uses the `rgeo` gem, which has additional dependencies. Please see the README documentation for `rgeo` for more information: https://github.com/rgeo/rgeo -## Creating a Spatial Rails App +## Setup -This section covers starting a new Rails application from scratch. If you need -to add geospatial capabilities to an existing Rails application (i.e. you need -to convert a non-spatial database to a spatial database), see the section on -"Upgrading a Database With Spatial Features" below. +If you have not created your rails app yet start there. -To create a new Rails application using `activerecord-postgis-adapter`, start by -using the postgresql adapter. - -```rake +```sh rails new my_app --database=postgresql ``` -Add the adapter gem to the Gemfile: +Add the gem to your Gemfile. ```ruby gem 'activerecord-postgis-adapter' ``` -Once you have set up your database config, run: +And tell ActiveRecord to use the adapter by setting the `adapter` field in `config/database.yml` -```rake -rake db:create +```yml +default: &default + adapter: postgis ``` -to create your development database. +Create the database if you haven't already. -Then, create a migration to add the PostGIS extension to your database. -```rake -rails g migration AddPostgisExtensionToDatabase -``` -The migration should look something like this: -```ruby -class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0] - def change - enable_extension 'postgis' - end -end -``` - -Then run the migration: -```rake -rails db:migrate +```sh +rake db:create ``` -Once you have installed the adapter, edit your `config/database.yml` as described above. - -## Upgrading an Existing Database +Create a migration to add the PostGIS extension to your database. -If you have an existing Rails app that uses Postgres, -and you want to add geospatial features, follow these steps. - -First, add the `activerecord-postgis-adapter` gem to the Gemfile, and update -your bundle by running `bundle install`. - -Then, create a migration to add the PostGIS extension to your database. -```rake -rails g migration AddPostgisExtensionToDatabase +```sh +rails generate migration AddPostgisExtensionToDatabase ``` + The migration should look something like this: ```ruby class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0] @@ -291,8 +264,9 @@ class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0] end ``` -Then run the migration: -```rake +Then run the migration. + +```sh rails db:migrate ```