In pg 9.3 database for rails 3.2
app, table engine_configs keeps losing primary key (id) and its indexes. Here is the table:
For the table shown above, we just added the primary key again and it is showing integer in column ID instead of serial. Last week, we had manually re-created key and indexes on the table and verified that those key and indexes did exist. There were only a few pg_dump
and pg_restore
on the table before we found that primary key and indexes are missing again. There was no db crash or something similar. Is there any explanation of why this happens and how to prevent it from happening again? This problem literally blows up our rails app.
UPDATE:
Here is the rails db create:
class CreateAuthentifyEngineConfigs < ActiveRecord::Migration
def change
create_table :authentify_engine_configs do |t|
#t.integer :client_id
t.string :engine_name
t.string :engine_version
t.string :argument_name
t.text :argument_value
t.integer :last_updated_by_id
t.timestamps
t.string :brief_note
t.boolean :global, :default => false
end
add_index :authentify_engine_configs, :engine_name
add_index :authentify_engine_configs, :argument_name
add_index :authentify_engine_configs, [:engine_name, :argument_name], :name => :authentify_engine_configs_names
end
end
This migration file has been used many times with sqlite3 and never had any problem.
UPDATE1:
After pg_dump -Fc --table=authentify_engine_configs mydb > mydb_ec.backup
, then restore with:
pg_restore --clean --dbname=mydevdb --table=authentify_engine_configs --verbose c:\d\code\rails_proj\cis\db\mydb_ec.backup
The indexes were lost with the restored local copy. However when pg_dump the whole db, then restored copy is fine.