Class: DbSchema::Runner
- Inherits:
-
Object
- Object
- DbSchema::Runner
- Defined in:
- lib/db_schema/runner.rb
Instance Attribute Summary collapse
-
#changes ⇒ Object
readonly
Returns the value of attribute changes.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(changes, connection) ⇒ Runner
constructor
A new instance of Runner.
- #run! ⇒ Object
Constructor Details
#initialize(changes, connection) ⇒ Runner
Returns a new instance of Runner.
5 6 7 8 |
# File 'lib/db_schema/runner.rb', line 5 def initialize(changes, connection) @changes = changes @connection = connection end |
Instance Attribute Details
#changes ⇒ Object (readonly)
Returns the value of attribute changes.
3 4 5 |
# File 'lib/db_schema/runner.rb', line 3 def changes @changes end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
3 4 5 |
# File 'lib/db_schema/runner.rb', line 3 def connection @connection end |
Class Method Details
.default_to_sequel(default) ⇒ Object
239 240 241 242 243 244 245 |
# File 'lib/db_schema/runner.rb', line 239 def default_to_sequel(default) if default.is_a?(Symbol) Sequel.lit(default.to_s) else default end end |
.map_options(type, options) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/db_schema/runner.rb', line 204 def (type, ) mapping = case type when :char, :varchar, :bit, :varbit Utils.rename_keys(, length: :size) when :numeric Utils.rename_keys() do || precision, scale = Utils.delete_at(, :precision, :scale) if precision if scale [:size] = [precision, scale] else [:size] = precision end end end when :interval Utils.rename_keys(, precision: :size) do || [:type] = "INTERVAL #{.delete(:fields).upcase}" end when :array Utils.rename_keys() do || [:type] = "#{.delete(:element_type)}[]" end else end if mapping.key?(:default) mapping.merge(default: default_to_sequel(mapping[:default])) else mapping end end |
Instance Method Details
#run! ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/db_schema/runner.rb', line 10 def run! changes.each do |change| case change when Operations::CreateTable create_table(change) when Operations::DropTable drop_table(change) when Operations::RenameTable rename_table(change) when Operations::AlterTable alter_table(change) when Operations::CreateForeignKey create_foreign_key(change) when Operations::DropForeignKey drop_foreign_key(change) when Operations::CreateEnum create_enum(change) when Operations::DropEnum drop_enum(change) when Operations::RenameEnum rename_enum(change) when Operations::AlterEnumValues alter_enum_values(change) when Operations::CreateExtension create_extension(change) when Operations::DropExtension drop_extension(change) when Operations::ExecuteQuery execute_query(change) end end end |