Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added the ability to reset schema migrations table when creating a fr…

…esh migration from schema.db

Signed-off-by: PJ Hyett <pjhyett@gmail.com>
  • Loading branch information...
commit cb2b0f36a60c8ec8c62354e8f29109c66afb50fb 1 parent 4154d21
@mlightner mlightner authored committed
Showing with 15 additions and 6 deletions.
  1. +10 −6 lib/auto_migrations.rb
  2. +5 −0 tasks/auto_migrations_tasks.rake
View
16 lib/auto_migrations.rb
@@ -18,12 +18,16 @@ class << ActiveRecord::Schema
end
end
- def self.schema_to_migration
- schema = File.read(File.join(RAILS_ROOT, "db", "schema.rb"))
- schema.gsub!(/#(.)+\n/, '')
- schema.sub!(/ActiveRecord::Schema.define(.+)do[ ]?\n/, '')
- schema.gsub!(/^/, ' ')
- schema = "class InitialSchema < ActiveRecord::Migration\n def self.up\n" + schema
+ def self.schema_to_migration(with_reset = false)
+ schema_in = File.read(File.join(RAILS_ROOT, "db", "schema.rb"))
+ schema_in.gsub!(/#(.)+\n/, '')
+ schema_in.sub!(/ActiveRecord::Schema.define(.+)do[ ]?\n/, '')
+ schema_in.gsub!(/^/, ' ')
+ schema = "class InitialSchema < ActiveRecord::Migration\n def self.up\n"
+ schema += " # We're resetting the migrations database...\n" +
+ " drop_table :schema_migrations\n" +
+ " initialize_schema_migrations_table\n\n" if with_reset
+ schema += schema_in
schema << "\n def self.down\n"
schema << (ActiveRecord::Base.connection.tables - %w(schema_info schema_migrations)).map do |table|
" drop_table :#{table}\n"
View
5 tasks/auto_migrations_tasks.rake
@@ -11,5 +11,10 @@ namespace :db do
task :to_migration => :environment do
AutoMigrations.schema_to_migration
end
+
+ desc "Create migration from schema.rb and reset migrations log"
+ task :to_migration_with_reset => :environment do
+ AutoMigrations.schema_to_migration(true)
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.