# Fixes wrong database structure created by ChronoModel's issue #23 # # https://github.com/ifad/chronomodel/issues/23 # # Download this file in your app root, and then run # # rails run ./chronomodel-fix-db-issue-23.rb # # Sorry for the hassle :-). # # - vjt # conn = ActiveRecord::Base.connection Dir['./app/models/**/*.rb'].sort.each {|f| require f} chrono_tables = ChronoModel::TimeMachine.chrono_models.keys conn.transaction do chrono_tables.each do |t| print "Fixing #{t}..." pk = conn.primary_key(t) conn.execute "alter table history.#{t} drop constraint #{t}_timeline_consistency" conn.execute "alter table history.#{t} add constraint #{t}_timeline_consistency exclude using gist(#{pk} with =, validity with &&)" puts "done" end end