vendredi 26 mai 2017

How to check if schema exists in Ruby on Rails migration

I'm using Rails 5.0.2, Postgresql as database and Heroku Connect to syncronize data with salesforce.

I've already had the public schema when are created the tables of the application but Heroku Connect writes on the same database salesforce's tables. I need to add a field in a table of salesforce schema.

I've found the method schema_exists? (http://ift.tt/2r4kxXu) but i don't know how to implement it, i'm new on RoR.

This is my migration code:

class CreateSchema < ActiveRecord::Migration[5.0]
      def change
    if !schema_exists?('salesforce')
      execute "CREATE SCHEMA salesforce"
    end
    if !table_exists?('salesforce.ontap__order__c')
      create_table 'salesforce.ontap__order__c'
    end
    add_column :'salesforce.ontap__order__c', :currencyisomode, :string
    if !table_exists?('salesforce.ontap__order_item__c')
      create_table 'salesforce.ontap__order_item__c'
    end
    add_column :'salesforce.ontap__order_item__c', :currencyisomode, :string
  end
end

What i'm doing wrong?

Aucun commentaire:

Enregistrer un commentaire