Class: Zdm::Table
- Inherits:
-
Object
- Object
- Zdm::Table
- Defined in:
- lib/zdm.rb
Instance Attribute Summary collapse
-
#archive ⇒ Object
readonly
Returns the value of attribute archive.
-
#copy ⇒ Object
readonly
Returns the value of attribute copy.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
-
#statements ⇒ Object
readonly
Returns the value of attribute statements.
Instance Method Summary collapse
- #add_column(name, definition) ⇒ Object
- #alter(definition) ⇒ Object
- #change_column(name, definition) ⇒ Object
- #ddl(statement) ⇒ Object
-
#initialize(name) ⇒ Table
constructor
A new instance of Table.
- #remove_column(name) ⇒ Object
- #rename_column(old_name, new_name) ⇒ Object
Constructor Details
#initialize(name) ⇒ Table
Returns a new instance of Table.
109 110 111 112 113 114 |
# File 'lib/zdm.rb', line 109 def initialize(name) @origin = name @copy = "zdm_#{name}" @archive = "zdma_#{Time.now.strftime("%Y%m%d_%H%M%S%N")}_#{name}"[0..64] @statements = [] end |
Instance Attribute Details
#archive ⇒ Object (readonly)
Returns the value of attribute archive.
107 108 109 |
# File 'lib/zdm.rb', line 107 def archive @archive end |
#copy ⇒ Object (readonly)
Returns the value of attribute copy.
107 108 109 |
# File 'lib/zdm.rb', line 107 def copy @copy end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
107 108 109 |
# File 'lib/zdm.rb', line 107 def origin @origin end |
#statements ⇒ Object (readonly)
Returns the value of attribute statements.
107 108 109 |
# File 'lib/zdm.rb', line 107 def statements @statements end |
Instance Method Details
#add_column(name, definition) ⇒ Object
124 125 126 |
# File 'lib/zdm.rb', line 124 def add_column(name, definition) ddl('ALTER TABLE `%s` ADD COLUMN `%s` %s' % [@copy, name, definition]) end |
#alter(definition) ⇒ Object
120 121 122 |
# File 'lib/zdm.rb', line 120 def alter(definition) ddl('ALTER TABLE `%s` %s' % [@copy, definition]) end |
#change_column(name, definition) ⇒ Object
128 129 130 |
# File 'lib/zdm.rb', line 128 def change_column(name, definition) ddl('ALTER TABLE `%s` MODIFY COLUMN `%s` %s' % [@copy, name, definition]) end |
#ddl(statement) ⇒ Object
116 117 118 |
# File 'lib/zdm.rb', line 116 def ddl(statement) @statements << statement end |
#remove_column(name) ⇒ Object
132 133 134 |
# File 'lib/zdm.rb', line 132 def remove_column(name) ddl('ALTER TABLE `%s` DROP `%s`' % [@copy, name]) end |
#rename_column(old_name, new_name) ⇒ Object
136 137 138 |
# File 'lib/zdm.rb', line 136 def rename_column(old_name, new_name) raise "Unsupported: you must first run a migration adding the column `#{new_name}`, deploy the code live, then run another migration at a later time to remove the column `#{old_name}`" end |