2012-04-16 81 views
4

我可以转储当前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! 

回答

1

一种方式可以通过Migrations

  1. 完成从数据库转储中的副本: -

    sequel -d mysql://[email protected]/database1 > db/001_test.rb

  2. 编辑只包括所需要的表。

  3. 运行迁移到新的数据库: -

    sequel -m db/ mysql://[email protected]/database2