Topic: How to use RailsOnPg

Dear all,

Today I found this promising plugin that facilitates the creation of certain assets in Postgresql databases. Being able to create foreign keys from a migration would be really useful.

After installing the plugin (which I did using the command rails plugin install since the one suggested at git doesn't work) I created an additional migration with the following content:

class ForeignKeys < ActiveRecord::Migration
  def up
    add_foreign_key :data_sets, :city_id, :cities
  end

  def down
    remove_foreign_key :data_sets, :city_id, :cities
  end
end

Running db:migrate I get the following output:

==  ForeignKeys: migrating ====================================================
-- add_foreign_key(:data_sets, :city_id, :cities)
rake aborted!
An error has occurred, this and all later migrations canceled:

undefined method `add_foreign_key' for #<ForeignKeys:0x000000039b6038>

Tasks: TOP => db:migrate
(See full trace by running task with --trace)

I'm relatively new to Rails, so my apologies if these questions are basic. It seems the plugin is not functioning or inactive, do I need to do something else apart from the install? Is there some way I can verify this plugin was effectively installed?

Thank you very much.

Re: How to use RailsOnPg

The plugin is somewhat old,  are you using Rails 3.X?  It may not work on the latest version.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: How to use RailsOnPg

Hi Brad, thank you for your reply.

Indeed I'm using a recent version of Rails, 3.something. Assuming that this plugin is outdated, is there anything similar around I could use for the same purpose?

Thanks.

Re: How to use RailsOnPg

My first gut reaction is just brute force it.  You can always put raw SQL in your migration.  That plugin doesn't save you THAT much effort.

Joe got a job, on the day shift, at the Utility Muffin Research Kitchen, arrogantly twisting the sterile canvas snout of a fully charged icing anointment utensil.

Re: How to use RailsOnPg

BradHodges wrote:

My first gut reaction is just brute force it.  You can always put raw SQL in your migration.

Actually that's sounds very good. Unfortunately I don't know how to do it smile. Can you point me to a quick example I may learn from?

Thank you once more.

Re: How to use RailsOnPg

I just learned about connection.execute and it serves pretty well. Knowing about this handy command I don't exactly understand the purpose of RailOnPg. But well, case closed.

Last edited by lads (2011-11-28 11:47:18)

Re: How to use RailsOnPg

I know this thread is months old, but I thought I'd share something interesting that I came across.

From the guides provided by RubyonRails.org (http://guides.rubyonrails.org/migrations.html) you can add the foreigner gem (https://github.com/matthuhiggins/foreigner) to your gem file, bundle install, and use the add_foreign_key method in your migrations.