我可以转储当前的Database#schema,但是我想用该架构创建一个新表(在不同的数据库中),但是我不知道如何做到这一点?
DB = Sequel.connect('sqlite:///database_from.db')
schema = DB.schema :table
# schema => [[:id, {:auto_increment=>true, :allow_null=>false, :default=>nil, :primary_key=>true, :db_type=>"smallint(5) unsigned", :type=>:integer, :ruby_default=>nil}], [:field, {:allow_null=>true, :default=>nil, :primary_key=>false, :db_type=>"smallint(5) unsigned", :type=>:integer, :ruby_default=>nil}]]
DB2 = Sequel.connect('sqlite:///database_to.db')
DB2.create_table('table name', schema) #< allowing this would be cool!
答案 0 :(得分:2)
可以通过Migrations
完成一种方式从数据库中转储副本: -
sequel -d mysql://root@localhost/database1 > db/001_test.rb
编辑以仅包含所需的表格。
运行迁移到新数据库: -
sequel -m db/ mysql://root@localhost/database2