Skip to content

Commit

Permalink
Merge pull request #392 from frehoy/readme-reword-create-extension
Browse files Browse the repository at this point in the history
Clarify extension creation instructions in README
  • Loading branch information
keithdoggett committed Feb 23, 2024
2 parents 90d5f65 + a06b54e commit a812279
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions README.md
Expand Up @@ -222,48 +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. The adapter will add the PostGIS extension to your database.

Once you have installed the adapter, edit your `config/database.yml` as described above.

## Upgrading an Existing Database
Create the database if you haven't already.

If you have an existing Rails app that uses Postgres,
and you want to add geospatial features, follow these steps.
```sh
rake db:create
```

First, add the `activerecord-postgis-adapter` gem to the Gemfile, and update
your bundle by running `bundle install`.
Create a migration to add the PostGIS extension to your database.

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]
Expand All @@ -273,8 +264,9 @@ class AddPostgisExtensionToDatabase < ActiveRecord::Migration[7.0]
end
```

Then run the migration:
```rake
Then run the migration.

```sh
rails db:migrate
```

Expand Down

0 comments on commit a812279

Please sign in to comment.