here I come with this problem.
Here we have this host with a full system written in RoR with a considerable amount of data of users into a Postgresql database.
Then, in a separate local host, we have a wordpress page that runs certain applications powered with buddypress plugin (allows custom fields) and of course uses a MySQL database.
What do I need is: to transfer the user data from the Postgresql database into the MySQL one. I'm aware that is possible to create users in Wordpress by inserting data into the database, but I need the query to transfer the same user data from the first database.
I have been thinking in a cronjob with php. (Just unsure how to do the query when they are two different hosts and having to use mysql_connect and pg_connect).
I've created a view in postgresql with the data I need to migrate.
I've also been suggested to try out "Navicat", but unsure if it can do what I exactly need to do.
What would be the way to go? Thanks.
if you can access both the databases, you can write two classes , one derived from mysql
and other from postgres
Ex:
#config/database.yml
development: &DEV
adapter: postgresql
host: localhost
database: postgresql_db
username:
password:
wordpress: &WORDPRESS
adapter: mysql2
host: localhost
username:
password:
database: wordpress
wordpress_development:
<<: *DEV
and you may have a base class for wordpress
class WordpressBase < ActiveRecord::Base
WordpressRecord.establish_connection({
adapter: "mysql2",
host: ENV['MYSQL_HOST'],
username: ENV['MYSQL_USER'],
password: ENV['MYSQL_PASS'],
database: ENV['MYSQL_DB']
})
self.abstract_class = true
end
and now you can use normal active record to migrate data
Ex:
class A < ActiveRecord::Base
# connects to your postgres
end
class B < WordpressBase
# connects to your mysql
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.