Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed an annoying issues with Rails migration generators that won't g…

…enerator more than 1 migration at time.
  • Loading branch information...
commit 1a9e4a3d4f0accd55845fa94e1ce8c008e74fa9e 1 parent d5299bb
@markbates markbates authored
View
2  Rakefile
@@ -4,7 +4,7 @@ require 'gemstub'
Gemstub.test_framework = :rspec
Gemstub.gem_spec do |s|
- s.version = "0.2.0"
+ s.version = "0.2.1"
s.rubyforge_project = "magrathea"
s.add_dependency('configatron')
s.email = 'mark@markbates.com'
View
6 apn_on_rails.gemspec
@@ -2,15 +2,15 @@
Gem::Specification.new do |s|
s.name = %q{apn_on_rails}
- s.version = "0.2.0.20090727132135"
+ s.version = "0.2.1.20090730113724"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["markbates"]
- s.date = %q{2009-07-27}
+ s.date = %q{2009-07-30}
s.description = %q{apn_on_rails was developed by: markbates}
s.email = %q{mark@markbates.com}
s.extra_rdoc_files = ["README", "LICENSE"]
- s.files = ["lib/apn_on_rails/apn_on_rails.rb", "lib/apn_on_rails/app/models/apn/device.rb", "lib/apn_on_rails/app/models/apn/notification.rb", "lib/apn_on_rails/tasks/apn.rake", "lib/apn_on_rails/tasks/db.rake", "lib/apn_on_rails.rb", "lib/apn_on_rails_tasks.rb", "README", "LICENSE", "generators/apn_migrations_generator.rb", "generators/templates/apn_migrations/create_apn_devices.rb", "generators/templates/apn_migrations/create_apn_notifications.rb"]
+ s.files = ["lib/apn_on_rails/apn_on_rails.rb", "lib/apn_on_rails/app/models/apn/device.rb", "lib/apn_on_rails/app/models/apn/notification.rb", "lib/apn_on_rails/tasks/apn.rake", "lib/apn_on_rails/tasks/db.rake", "lib/apn_on_rails.rb", "lib/apn_on_rails_tasks.rb", "README", "LICENSE", "generators/apn_migrations_generator.rb", "generators/templates/apn_migrations/001_create_apn_devices.rb", "generators/templates/apn_migrations/002_create_apn_notifications.rb"]
s.homepage = %q{http://www.metabates.com}
s.require_paths = ["lib"]
s.rubyforge_project = %q{magrathea}
View
22 generators/apn_migrations_generator.rb
@@ -4,10 +4,22 @@ class ApnMigrationsGenerator < Rails::Generator::Base
def manifest # :nodoc:
record do |m|
- [:create_apn_devices, :create_apn_notifications].each do |f|
- m.migration_template(File.join('apn_migrations', "#{f}.rb"), "db/migrate", {:migration_file_name => f, :collision => :skip})
+ timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
+ db_migrate_path = File.join('db', 'migrate')
+
+ m.directory(db_migrate_path)
+
+ ['001_create_apn_devices', '002_create_apn_notifications'].each_with_index do |f, i|
+ timestamp = timestamp.succ
+ if Dir.glob(File.join(db_migrate_path, "*_#{f}.rb")).empty?
+ m.file(File.join('apn_migrations', "#{f}.rb"),
+ File.join(db_migrate_path, "#{timestamp}_#{f}.rb"),
+ {:collision => :skip})
+ end
end
- end
- end
+
+ end # record
+
+ end # manifest
-end
+end # ApnMigrationsGenerator
View
0  ...rs/templates/apn_migrations/create_apn_devices.rb → ...emplates/apn_migrations/001_create_apn_devices.rb
File renamed without changes
View
0  ...plates/apn_migrations/create_apn_notifications.rb → ...es/apn_migrations/002_create_apn_notifications.rb
File renamed without changes
View
8 spec/active_record/setup_ar.rb
@@ -6,12 +6,14 @@
ActiveRecord::Base.logger = logger
db_file = File.join(File.dirname(__FILE__), 'test.db')
-# FileUtils.rm(db_file) if File.exists?(db_file)
-File.open(db_file, 'w')
+FileUtils.rm(db_file) if File.exists?(db_file)
+# File.open(db_file, 'w')
ActiveRecord::Base.establish_connection({
:adapter => 'sqlite3',
:dbfile => db_file
})
-ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'apn_on_rails', 'db', 'migrate'))
+ActiveRecord::Migrator.up(File.join(File.dirname(__FILE__), '..', '..', 'generators', 'templates', 'apn_migrations'))
+
+# raise hell
Please sign in to comment.
Something went wrong with that request. Please try again.