Skip to content

Instantly share code, notes, and snippets.

@huacnlee
Created August 3, 2010 01:19
Show Gist options
  • Save huacnlee/505658 to your computer and use it in GitHub Desktop.
Save huacnlee/505658 to your computer and use it in GitHub Desktop.
# Rails migrate 克隆表结构
class CreateArticleClones < ActiveRecord::Migration
def self.up
create_table :article_clones do |t|
# 从 Article 的 columns 里面找,注意! Article 的表结构必须在这个 Migrate 之前有创建!
Article.columns.each do |col|
next if col.name == "id"
t.send(col.type.to_sym, col.name.to_sym, :null => col.null,
:limit => col.limit, :default => col.default, :scale => col.scale,
:precision => col.precision)
end
end
end
def self.down
drop_table :article_clones
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment