Postgresql ROR:如何将一个表中的数据从一个数据库复制到另一个表中,该表位于另一个在heroku中具有不同表属性的数据库中?
在一个数据库中,我有一个属性为col_1、col_2、col_3的Products表,在另一个数据库中,我有一个属性为product_name、product_price、product_count的Products表。如何在Heroku中将数据从列1复制或移动到Product_price,从列2复制或移动到Product_name 关于您的设置,我有很多问题,但我会尝试一下 在我的“产品”模型中Postgresql ROR:如何将一个表中的数据从一个数据库复制到另一个表中,该表位于另一个在heroku中具有不同表属性的数据库中?,postgresql,ruby-on-rails-4,ruby-on-rails-5,heroku-postgres,Postgresql,Ruby On Rails 4,Ruby On Rails 5,Heroku Postgres,在一个数据库中,我有一个属性为col_1、col_2、col_3的Products表,在另一个数据库中,我有一个属性为product_name、product_price、product_count的Products表。如何在Heroku中将数据从列1复制或移动到Product_price,从列2复制或移动到Product_name 关于您的设置,我有很多问题,但我会尝试一下 在我的“产品”模型中 #app/models/product.rb 类别产品
#app/models/product.rb
类别产品<应用记录
...
创建之后:传播到db2
...
私有的
def将_传播到_db2
#连接到db2
sql=“插入到产品中(‘产品价格’、‘产品名称’)
价值观
(#{col_1},#{col_2})
#执行sql
结束
结束
如果我对您的系统有更好的了解,我可能会做得更多,但我希望这有助于您如何连接到这两个数据库?我没有连接数据库…是否可以使用pg db备份进行数据移动是否可以使用postgres数据库备份
# app/models/product.rb
Class Product < ApplicationRecord
...
after_create :propagate_to_db2
...
private
def propagate_to_db2
#connect_to_db2
sql = "INSERT INTO products ( 'Product_price', 'product_name' )
VALUES
(#{col_1}, #{col_2})"
#execute sql
end
end