Ticket #6799: timestamped_migrations.v1.patch
| File timestamped_migrations.v1.patch, 3.6 kB (added by francois.beausoleil, 2 years ago) |
|---|
-
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
old new 239 239 rescue ActiveRecord::StatementInvalid 240 240 # Schema has been intialized 241 241 end 242 243 begin 244 execute "CREATE TABLE #{ActiveRecord::Migrator.schema_migrations_table_name} (migration #{type_to_sql(:string, 14)}, migrated_at #{type_to_sql(:datetime)})" 245 execute "CREATE INDEX by_migration ON #{ActiveRecord::Migrator.schema_migrations_table_name}(migration)" 246 rescue ActiveRecord::StatementInvalid 247 # Schema has been intialized 248 end 242 249 end 243 250 244 251 def dump_schema_information #:nodoc: -
vendor/rails/activerecord/lib/active_record/migration.rb
old new 303 303 def schema_info_table_name 304 304 Base.table_name_prefix + "schema_info" + Base.table_name_suffix 305 305 end 306 307 def schema_migrations_table_name 308 Base.table_name_prefix + "schema_migrations" + Base.table_name_suffix 309 end 306 310 307 311 def current_version 308 (Base.connection.select_one("SELECT version FROM #{schema_info_table_name}") || {"version" => 0})["version"].to_i312 (Base.connection.select_one("SELECT MAX(migration) AS migration FROM #{schema_migrations_table_name}") || {"migration" => 0})["migration"].to_i 309 313 end 310 314 311 315 def proper_table_name(name) … … 370 374 end 371 375 372 376 def set_schema_version(version) 373 Base.connection.update("UPDATE #{self.class.schema_info_table_name} SET version = #{down? ? version.to_i - 1 : version.to_i}") 377 if down? then 378 Base.connection.delete("DELETE FROM #{self.class.schema_migrations_table_name} WHERE migration = #{version}") 379 else 380 Base.connection.insert("INSERT INTO #{self.class.schema_migrations_table_name}(migration, migrated_at) VALUES (#{version}, '#{Time.now.utc.to_formatted_s(:db)}')") 381 end 374 382 end 375 383 376 384 def up? … … 386 394 end 387 395 388 396 def irrelevant_migration?(version) 389 (up? && version.to_i <= current_version) || (down? && version.to_i > current_version) 397 count = Base.connection.select_values("SELECT COUNT(*) FROM #{self.class.schema_migrations_table_name} WHERE migration = #{version}").first 398 !(count.blank? || count.to_i.zero?) 390 399 end 391 400 end 392 401 end -
vendor/rails/railties/lib/rails_generator/commands.rb
old new 1 $stderr.puts "loading vendor/rails/railties/lib/rails_generator/commands.rb" 1 2 require 'delegate' 2 3 require 'optparse' 3 4 require 'fileutils' … … 76 77 end 77 78 78 79 def next_migration_number 79 current_migration_number + 180 Time.now.utc.strftime('%Y%m%d%H%M%S').to_i 80 81 end 81 82 82 def next_migration_string(padding = 3)83 def next_migration_string(padding = 14) 83 84 "%.#{padding}d" % next_migration_number 84 85 end 85 86