Immigrate adds methods to ActiveRecord::Migration to create and manage foreign-data wrappers in PostgreSQL.
Add this line to your application's Gemfile:
gem 'immigrate'And then execute:
$ bundle install
You will need to have a connection to a remote server before you can create a foreign table. This connection has to be created with connection information and user credentials for the foreign server in a config/immigrate.yml file:
development:
foreign_server:
host: 192.83.123.89
port: 5432
dbname: foreign_db
user: foreign_user
password: password
production:
foreign_server:
host: 192.83.123.90
port: 5432
dbname: foreign_db
user: foreign_user
password: passwordNext you will need to create a migration to create the connection using a standard migration file like `db/migrate/[TIMESTAMP]_create_foreign_connection.rb:
class CreateForeignConnection < ActiveRecord::Migration[5.0]
def change
create_foreign_connection :foreign_server
end
endThen you can run the migration as usual:
$ rake db:mibrateOnce you have a foreign connection you can now create migrations for the foreign tables you need to access in your application. This also goes in a standard migration file:
class CreatePost < ActiveRecord::Migration[5.0]
def change
create_foreign_table :posts do |t|
t.string :title
t.text :body
end
end
endAnd once again you can run your migrations as usual:
$ rake db:mibrateAfter checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/ratdaddy/immigrate. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.