Class | DataMapper::Migration::Table |
In: |
lib/data_mapper/migration.rb
lib/data_mapper/migration.rb |
Parent: | Object |
MAPPINGS | = | DataMapper::Adapters::Sql::Mappings unless defined?(MAPPINGS) |
MAPPINGS | = | DataMapper::Adapters::Sql::Mappings unless defined?(MAPPINGS) |
name | [RW] | |
name | [RW] |
# File lib/data_mapper/migration.rb, line 22 22: def self.add_column(table, column, type, options = {}) 23: column = table.add_column column, type, options 24: column.create! 25: end
# File lib/data_mapper/migration.rb, line 22 22: def self.add_column(table, column, type, options = {}) 23: column = table.add_column column, type, options 24: column.create! 25: end
# File lib/data_mapper/migration.rb, line 18 18: def self.drop(table_name) 19: database.table(klass(table_name)).drop! 20: end
# File lib/data_mapper/migration.rb, line 18 18: def self.drop(table_name) 19: database.table(klass(table_name)).drop! 20: end
# File lib/data_mapper/migration.rb, line 81 81: def self.klass(table) 82: table_name = table.to_s 83: class_name = Inflector::classify(table_name) 84: klass = Inflector::constantize(class_name) 85: rescue NameError 86: module_eval "class ::\#{class_name} < DataMapper::Base\nend\n" 87: klass = eval("#{class_name}") 88: ensure 89: klass 90: end
# File lib/data_mapper/migration.rb, line 81 81: def self.klass(table) 82: table_name = table.to_s 83: class_name = Inflector::classify(table_name) 84: klass = Inflector::constantize(class_name) 85: rescue NameError 86: module_eval "class ::\#{class_name} < DataMapper::Base\nend\n" 87: klass = eval("#{class_name}") 88: ensure 89: klass 90: end
# File lib/data_mapper/migration.rb, line 9 9: def initialize(table = nil, options = {}) 10: @name, @options = table, options 11: @columns = [] 12: end
# File lib/data_mapper/migration.rb, line 9 9: def initialize(table = nil, options = {}) 10: @name, @options = table, options 11: @columns = [] 12: end
# File lib/data_mapper/migration.rb, line 27 27: def self.remove_column(table, column) 28: column = table[column] 29: column.drop! 30: end
# File lib/data_mapper/migration.rb, line 27 27: def self.remove_column(table, column) 28: column = table[column] 29: column.drop! 30: end
# File lib/data_mapper/migration.rb, line 32 32: def add(column, type, options = {}) 33: column_data = [column, type, options] 34: exists? ? self.class.add_column(table, *column_data) : table.add_column(*column_data) 35: end
# File lib/data_mapper/migration.rb, line 32 32: def add(column, type, options = {}) 33: column_data = [column, type, options] 34: exists? ? self.class.add_column(table, *column_data) : table.add_column(*column_data) 35: end
# File lib/data_mapper/migration.rb, line 58 58: def after_create! 59: unless exists? 60: table.add_column(:id, :integer, { :key => true }) unless @options[:id] == false 61: self.class.create(table) 62: end 63: end
# File lib/data_mapper/migration.rb, line 58 58: def after_create! 59: unless exists? 60: table.add_column(:id, :integer, { :key => true }) unless @options[:id] == false 61: self.class.create(table) 62: end 63: end
# File lib/data_mapper/migration.rb, line 46 46: def alter(column, type, options = {}) 47: column = table[column] 48: column.type = type 49: column.options = options 50: column.parse_options! 51: column.alter! 52: end
# File lib/data_mapper/migration.rb, line 46 46: def alter(column, type, options = {}) 47: column = table[column] 48: column.type = type 49: column.options = options 50: column.parse_options! 51: column.alter! 52: end
Rails Style
# File lib/data_mapper/migration.rb, line 67 67: def column(name, type, options = {}) 68: add(name, type, options) 69: end
Rails Style
# File lib/data_mapper/migration.rb, line 67 67: def column(name, type, options = {}) 68: add(name, type, options) 69: end
# File lib/data_mapper/migration.rb, line 54 54: def exists? 55: database.table_exists?(klass) 56: end
# File lib/data_mapper/migration.rb, line 54 54: def exists? 55: database.table_exists?(klass) 56: end
# File lib/data_mapper/migration.rb, line 77 77: def klass 78: @klass ||= self.class.klass(self.name) 79: end
# File lib/data_mapper/migration.rb, line 77 77: def klass 78: @klass ||= self.class.klass(self.name) 79: end
# File lib/data_mapper/migration.rb, line 37 37: def remove(column) 38: self.class.remove_column table, column 39: end
# File lib/data_mapper/migration.rb, line 37 37: def remove(column) 38: self.class.remove_column table, column 39: end
# File lib/data_mapper/migration.rb, line 41 41: def rename(old_column, new_column) 42: column = table[old_column] 43: column.rename!(new_column) 44: end
# File lib/data_mapper/migration.rb, line 41 41: def rename(old_column, new_column) 42: column = table[old_column] 43: column.rename!(new_column) 44: end