I have 2 models in my ruby app (jurnal and jurnal_my) and i need to import data jurnal from mysql to postgresql.
This is my method :
jurnal_my.rb
establish_connection "mysql"
self.table_name = "jurnal"
def self.import_from_mysql
JurnalMy.all.each{|jurnal|
hash = {}
JurnalMy.first.attributes.delete_if{|attr|%w(ID CREATED_AT UPDATED_AT).include?(attr)}.map{|case_attr|case_attr}.each{|hash_attr|
hash = hash.merge(hash_attr[0].downcase => hash_attr[1])
}
Jurnal.create hash
}
end
database.yml
default: &default
adapter: postgresql
encoding: unicode
username: adit
password: xxxxxxx
pool: 5
development:
<<: *default
database: portalpos_development
mysql:
adapter: mysql2
encoding: utf8
username: root
password: xxxxxxx
database: app
test:
<<: *default
database: portalpos_test
When i try to import data to postgresql, it's working. But the result is wrong. Data jurnal in mysql :
J01
J02
J03
Data jurnal in postgresql (result) :
J01
J01
J01
Can you help me?