Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify extension creation instructions in README #392

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 19 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
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