5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/has_archive/migration_manager.rb', line 5
def self.create_archive_for(model)
@table_name = model.table_name
fail MigrationExistsException.new(@table_name) if Dir["db/migrate/*_create_archive_for_#{@table_name}.rb"].any?
template = "class CreateArchiveFor\#{@table_name.camelize} < ActiveRecord::Migration\n def change\ncreate_table :\#{@table_name.singularize}_archives do |t|\n\#{columns.map {|c| build_column(c) }.join(\"\\n\") }\n t.datetime :archived_at, null: false\nend\n\n\#{indexes.map {|i| build_index(i) }.join(\"\\n\") }\n end\nend\\n\n"
File.write("db/migrate/#{file_name('create_archive_for')}", template)
end
|