Single table inheritance introduce on mid of development

Hi Folks,

  1. I converting existing model to STI
  2. Existing model CtctContact
  3. ctct_contacts rename as contacts and add column called type in table.
  4. In model modified base class(CtctContact < Contact) during migration
    it’s show contacts table not found like that.

Any idea how to fix.

Thanks,
Dhamodharan.N

On 8 January 2013 07:00, DHAMODHARAN N [email protected] wrote:

Hi Folks,

  1. I converting existing model to STI
  2. Existing model CtctContact
  3. ctct_contacts rename as contacts and add column called type in table.
  4. In model modified base class(CtctContact < Contact) during migration it’s
    show contacts table not found like that.

Do you mean that it is the migration to change the table name and add
the type column that is failing?
Show us the failing code (just the section that is failing) and the
exact error message and stack trace.

Colin

Hi Colin L.,

Existin code ctct_contact.rb => class CtctContact < Contact

After changes ctct_contact.rb => class CtctContact < ActiveRecord::Base

Above changes works fine for me but we cant proceed with that changes
right?

Trace :

– add_index(:ctct_contacts, [:ctct_account_id, :email_address],
{:unique=>true})
-> 0.0732s
rake aborted!
An error has occurred, this and all later migrations canceled:

PG::Error: ERROR: relation “contacts” does not exist
LINE 4: WHERE a.attrelid = ‘“contacts”’::regclass
^
: SELECT a.attname, format_type(a.atttypid, a.atttypmod),
d.adsrc, a.attnotnull
FROM pg_attribute a LEFT JOIN pg_attrdef d
ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attrelid = ‘“contacts”’::regclass
AND a.attnum > 0 AND NOT a.attisdropped
ORDER BY a.attnum
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:in
async_exec' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1151:inexec_no_cache’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:664:in
block in exec_query' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:280:inblock in log’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activesupport-3.2.6/lib/active_support/notifications/instrumenter.rb:20:in
instrument' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract_adapter.rb:275:inlog’
/home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/active_record.rb:32:in
block in log_with_newrelic_instrumentation' /home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:242:intrace_execution_scoped’
/home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/active_record.rb:29:in
log_with_newrelic_instrumentation' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:663:inexec_query’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:1276:in
column_definitions' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/postgresql_adapter.rb:859:incolumns’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/schema_cache.rb:12:in
block in initialize' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:inyield’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:in
default' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:228:incolumns’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/model_schema.rb:237:in
columns_hash' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/inheritance.rb:19:indescends_from_active_record?’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/inheritance.rb:25:in
finder_needs_type_condition?' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/base.rb:455:inrelation’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/scoping/named.rb:37:in
scoped' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/querying.rb:5:infind’
/home/dhamodharan/project/application20Web/db/migrate/20121128075457_add_ctct_contact_uniqueness.rb:14:in
block in obfuscate_current_contacts' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:192:intransaction’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/transactions.rb:208:in
transaction' /home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:493:inblock in transaction_with_trace_ActiveRecord_self_name_transaction’
/home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:242:in
trace_execution_scoped' /home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:488:intransaction_with_trace_ActiveRecord_self_name_transaction’
/home/dhamodharan/project/application20Web/db/migrate/20121128075457_add_ctct_contact_uniqueness.rb:13:in
obfuscate_current_contacts' /home/dhamodharan/project/application20Web/db/migrate/20121128075457_add_ctct_contact_uniqueness.rb:9:inchange’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:407:in
block (2 levels) in migrate' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:407:inblock in migrate’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:123:in
with_connection' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:389:inmigrate’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:528:in
migrate' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:720:inblock (2 levels) in migrate’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:in
call' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:inblock in ddl_transaction’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/connection_adapters/abstract/database_statements.rb:192:in
transaction' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/transactions.rb:208:intransaction’
/home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:493:in
block in transaction_with_trace_ActiveRecord_self_name_transaction' /home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:242:intrace_execution_scoped’
/home/dhamodharan/.rvm/gems/[email protected]/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:488:in
transaction_with_trace_ActiveRecord_self_name_transaction' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:775:inddl_transaction’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:719:in
block in migrate' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:700:ineach’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:700:in
migrate' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:570:inup’
/home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/migration.rb:551:in
migrate' /home/dhamodharan/.rvm/gems/[email protected]/gems/activerecord-3.2.6/lib/active_record/railties/databases.rake:153:inblock (2 levels) in <top (required)>’

Migration1:
class RenameTableForMailchimp < ActiveRecord::Migration
def change
rename_table :ctct_contacts, :contacts
end
end

Migration2:
class AddTypeColumnForMailchimp < ActiveRecord::Migration
def change
add_column :contacts, :type, :string
end
end

On 8 January 2013 12:33, DHAMODHARAN N [email protected] wrote:

add_column :contacts, :type, :string
end

end

Please don’t top post, it makes it difficult to follow the thread.
Insert your replies inline at appropriate points.

The error you showed came from
/home/dhamodharan/project/application20Web/db/migrate/20121128075457_add_ctct_contact_uniqueness.rb:9:in
`change’ so it might be helpful to show that migration. I presume the
migrations above ran successfully and that you have checked in the
database that the table has been renamed and the type column added ok.

Colin

On Tue, Jan 8, 2013 at 6:58 PM, Colin L. [email protected]
wrote:

def change
`change’ so it might be helpful to show that migration. I presume the
migrations above ran successfully and that you have checked in the
database that the table has been renamed and the type column added ok.

Thanks Lot Colin L.,

Cause of issue is in that migration have data migration script(like
invoking CtctContact model) but current code CtctContact base class
Contact
so it try to search contact table.

Colin

On 8 January 2013 11:34, DHAMODHARAN N [email protected] wrote:

Hi Colin L.,

Existin code ctct_contact.rb => class CtctContact < Contact

After changes ctct_contact.rb => class CtctContact < ActiveRecord::Base

Above changes works fine for me but we cant proceed with that changes right?

I don’t understand what you mean. I thought you were moving /to/ STI,
not away from it.

PG::Error: ERROR: relation “contacts” does not exist
Show us the whole migration code please.

Colin

On Tue, Jan 8, 2013 at 7:41 PM, Colin L. [email protected]
wrote:

def change

post the full code of the migration rb file and the full error that
you are seeing when you run rake db:migrate.

Colin

sample code:
def change
add_index :ctct_contacts, [:ctct_account_id, :email_address], :unique
=>
true
obfuscate_current_contacts
end

def obfuscate_current_contacts
CtctContact.transaction do
CtctContact.find(:all).each do |c|
#some code with c object
end
end
end

Problem solved commenting obfuscate_current_contacts method invoking.
Cause of issue we are invoking current code base CtctContact base
class
Contact so its seeking contacts table.
But our table rename migration later.

Thanks,
Dhamodharan

On 8 January 2013 14:03, DHAMODHARAN N [email protected] wrote:

end
Insert your replies inline at appropriate points.

Cause of issue is in that migration have data migration script(like
invoking CtctContact model) but current code CtctContact base class Contact
so it try to search contact table.

Sorry, I still don’t know what you mean as you still have not posted
the code that is generating the error. If you still have a problem
post the full code of the migration rb file and the full error that
you are seeing when you run rake db:migrate.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs