Class DataMapper::Migration::Table
In: lib/data_mapper/migration.rb
lib/data_mapper/migration.rb
Parent: Object

Methods

add   add   add_column   add_column   after_create!   after_create!   alter   alter   column   column   create   create   drop   drop   exists?   exists?   klass   klass   klass   klass   new   new   remove   remove   remove_column   remove_column   rename   rename   table   table  

Constants

MAPPINGS = DataMapper::Adapters::Sql::Mappings unless defined?(MAPPINGS)
MAPPINGS = DataMapper::Adapters::Sql::Mappings unless defined?(MAPPINGS)

Attributes

name  [RW] 
name  [RW] 

Public Class methods

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/data_mapper/migration.rb, line 14
14:       def self.create(table)
15:         table.create!
16:       end

[Source]

    # File lib/data_mapper/migration.rb, line 14
14:       def self.create(table)
15:         table.create!
16:       end

[Source]

    # File lib/data_mapper/migration.rb, line 18
18:       def self.drop(table_name)
19:         database.table(klass(table_name)).drop!
20:       end

[Source]

    # File lib/data_mapper/migration.rb, line 18
18:       def self.drop(table_name)
19:         database.table(klass(table_name)).drop!
20:       end

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/data_mapper/migration.rb, line 9
 9:       def initialize(table = nil, options = {})
10:         @name, @options = table, options
11:         @columns = []
12:       end

[Source]

    # File lib/data_mapper/migration.rb, line 9
 9:       def initialize(table = nil, options = {})
10:         @name, @options = table, options
11:         @columns = []
12:       end

[Source]

    # File lib/data_mapper/migration.rb, line 27
27:       def self.remove_column(table, column)
28:         column = table[column]
29:         column.drop!
30:       end

[Source]

    # File lib/data_mapper/migration.rb, line 27
27:       def self.remove_column(table, column)
28:         column = table[column]
29:         column.drop!
30:       end

Public Instance methods

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # 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

[Source]

    # File lib/data_mapper/migration.rb, line 67
67:       def column(name, type, options = {})
68:         add(name, type, options)
69:       end

Rails Style

[Source]

    # File lib/data_mapper/migration.rb, line 67
67:       def column(name, type, options = {})
68:         add(name, type, options)
69:       end

[Source]

    # File lib/data_mapper/migration.rb, line 54
54:       def exists?
55:         database.table_exists?(klass)
56:       end

[Source]

    # File lib/data_mapper/migration.rb, line 54
54:       def exists?
55:         database.table_exists?(klass)
56:       end

[Source]

    # File lib/data_mapper/migration.rb, line 77
77:       def klass
78:         @klass ||= self.class.klass(self.name)
79:       end

[Source]

    # File lib/data_mapper/migration.rb, line 77
77:       def klass
78:         @klass ||= self.class.klass(self.name)
79:       end

[Source]

    # File lib/data_mapper/migration.rb, line 37
37:       def remove(column)
38:         self.class.remove_column table, column
39:       end

[Source]

    # File lib/data_mapper/migration.rb, line 37
37:       def remove(column)
38:         self.class.remove_column table, column
39:       end

[Source]

    # 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

[Source]

    # 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

klass!

[Source]

    # File lib/data_mapper/migration.rb, line 73
73:       def table
74:         @table ||= database.table(klass)
75:       end

klass!

[Source]

    # File lib/data_mapper/migration.rb, line 73
73:       def table
74:         @table ||= database.table(klass)
75:       end

[Validate]