Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

gemification and moving all vendored libs to vendor

  • Loading branch information...
commit 1c0dea6657460706b4d3d2bdce95283bf0338748 1 parent dec36de
@grosser grosser authored
View
9 README.markdown
@@ -7,9 +7,12 @@ Install Ruby, RubyGems then:
sudo gem install standalone_migrations
Add to `Rakefile` in your projects base directory:
- require 'rubygems'
- require 'standalone_migrations'
- StandaloneMigrations.tasks
+ begin
+ require 'standalone_migrations'
+ StandaloneMigrations.tasks
+ rescue LoadError
+ puts 'gem install standalone_migrations to get db:migrate:* tasks!'
+ end
Add database configuration to `config/database.yml` in your projects base directory e.g.:
development:
View
89 Rakefile
@@ -1,75 +1,18 @@
-APP_BASE = File.dirname(File.expand_path(__FILE__))
-
-# Add to load_path every "lib/" directory
-Dir["#{APP_BASE}/**/lib"].each { |p| $: << p }
-
-namespace :db do
- task :ar_init do
- require 'active_record'
- ENV['RAILS_ENV'] ||= 'development'
- config = YAML.load_file(APP_BASE + '/config/database.yml')[ENV['RAILS_ENV']]
- ActiveRecord::Base.establish_connection(config)
- logger = Logger.new $stderr
- logger.level = Logger::INFO
- ActiveRecord::Base.logger = logger
- end
-
- desc "Migrate the database using the scripts in the migrate directory. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
- task :migrate => :ar_init do
- require 'migration_helpers/init'
- ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
- ActiveRecord::Migrator.migrate(APP_BASE + "/migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
- Rake::Task[ "db:schema:dump" ].execute
+# rake install -> install gem locally (for tests)
+# rake release -> push to github and release to gemcutter
+# rake version:bump:patch -> increase version and add a git-tag
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gem|
+ gem.name = 'standalone_migrations'
+ gem.summary = "A thin wrapper to use Rails Migrations in non Rails projects"
+ gem.email = "grosser.michael@gmail.com"
+ gem.homepage = "http://github.com/thuss/standalone-migrations"
+ gem.authors = ["Michael Grosser"]
+ %w[rake activerecord].each{|d| gem.add_dependency d}
end
- namespace :schema do
- desc "Create schema.rb file that can be portably used against any DB supported by AR"
- task :dump => :ar_init do
- require 'active_record/schema_dumper'
- File.open(ENV['SCHEMA'] || APP_BASE + "/schema.rb", "w") do |file|
- ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
- end
- end
-
- desc "Load a ar_schema.rb file into the database"
- task :load => :ar_init do
- file = ENV['SCHEMA'] || APP_BASE + "/schema.rb"
- load(file)
- end
- end
-
- desc "Create a new migration"
- task :new_migration do |t|
- unless ENV['name']
- puts "Error: must provide name of migration to generate."
- puts "For example: rake #{t.name} name=add_field_to_form"
- exit 1
- end
-
- underscore = lambda { |camel_cased_word|
- camel_cased_word.to_s.gsub(/::/, '/').
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
- tr("-", "_").
- downcase
- }
-
- migration = underscore.call( ENV['name'] )
- file_name = "migrations/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration}.rb"
- class_name = migration.split('_').map { |s| s.capitalize }.join
-
- file_contents = <<eof
-class #{class_name} < ActiveRecord::Migration
- def self.up
- end
-
- def self.down
- raise ActiveRecord::IrreversibleMigration
- end
-end
-eof
- File.open(file_name, 'w') { |f| f.write file_contents }
-
- puts "Created migration #{file_name}"
- end
-end
+ Jeweler::GemcutterTasks.new
+rescue LoadError
+ puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
+end
View
1  VERSION
@@ -0,0 +1 @@
+0.1.0
View
1  config/.gitignore
@@ -1 +0,0 @@
-database.yml
View
0  config/database_sample.yml → database.yml
File renamed without changes
View
5 lib/standalone_migrations.rb
@@ -0,0 +1,5 @@
+class StandaloneMigrations
+ def self.tasks
+ load "#{File.dirname(__FILE__)}/../tasks/standalone_migrations.rake"
+ end
+end
View
1  migrations/.gitignore
@@ -1 +0,0 @@
-*.rb
View
44 standalone_migrations.gemspec
@@ -0,0 +1,44 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{standalone_migrations}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Michael Grosser"]
+ s.date = %q{2010-03-15}
+ s.email = %q{grosser.michael@gmail.com}
+ s.extra_rdoc_files = [
+ "README.markdown"
+ ]
+ s.files = [
+ ".gitignore",
+ "README.markdown",
+ "Rakefile"
+ ]
+ s.homepage = %q{http://github.com/thuss/standalone-migrations}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.6}
+ s.summary = %q{A thin wrapper to use Rails Migrations in non Rails projects}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<rake>, [">= 0"])
+ s.add_runtime_dependency(%q<activerecord>, [">= 0"])
+ else
+ s.add_dependency(%q<rake>, [">= 0"])
+ s.add_dependency(%q<activerecord>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<rake>, [">= 0"])
+ s.add_dependency(%q<activerecord>, [">= 0"])
+ end
+end
+
View
75 tasks/standalone_migrations.rake
@@ -0,0 +1,75 @@
+APP_BASE = File.expand_path('.') unless defined? APP_BASE
+
+# Add to load_path every "lib/" directory in vendor
+Dir["#{File.dirname(__FILE__)}/../vendor/**/lib"].each { |p| $LOAD_PATH << p }
+
+namespace :db do
+ task :ar_init do
+ require 'active_record'
+ ENV['RAILS_ENV'] ||= 'development'
+ config = YAML.load_file(APP_BASE + '/config/database.yml')[ENV['RAILS_ENV']]
+ ActiveRecord::Base.establish_connection(config)
+ logger = Logger.new $stderr
+ logger.level = Logger::INFO
+ ActiveRecord::Base.logger = logger
+ end
+
+ desc "Migrate the database using the scripts in the migrate directory. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
+ task :migrate => :ar_init do
+ require 'migration_helpers/init'
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
+ ActiveRecord::Migrator.migrate(APP_BASE + "/migrations/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
+ Rake::Task[ "db:schema:dump" ].execute
+ end
+
+ namespace :schema do
+ desc "Create schema.rb file that can be portably used against any DB supported by AR"
+ task :dump => :ar_init do
+ require 'active_record/schema_dumper'
+ File.open(ENV['SCHEMA'] || APP_BASE + "/schema.rb", "w") do |file|
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
+ end
+ end
+
+ desc "Load a ar_schema.rb file into the database"
+ task :load => :ar_init do
+ file = ENV['SCHEMA'] || APP_BASE + "/schema.rb"
+ load(file)
+ end
+ end
+
+ desc "Create a new migration"
+ task :new_migration do |t|
+ unless ENV['name']
+ puts "Error: must provide name of migration to generate."
+ puts "For example: rake #{t.name} name=add_field_to_form"
+ exit 1
+ end
+
+ underscore = lambda { |camel_cased_word|
+ camel_cased_word.to_s.gsub(/::/, '/').
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
+ tr("-", "_").
+ downcase
+ }
+
+ migration = underscore.call( ENV['name'] )
+ file_name = "migrations/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration}.rb"
+ class_name = migration.split('_').map { |s| s.capitalize }.join
+
+ file_contents = <<eof
+class #{class_name} < ActiveRecord::Migration
+ def self.up
+ end
+
+ def self.down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
+eof
+ File.open(file_name, 'w') { |f| f.write file_contents }
+
+ puts "Created migration #{file_name}"
+ end
+end
View
0  lib/migration_helpers/MIT-LICENSE → vendor/migration_helpers/MIT-LICENSE
File renamed without changes
View
0  lib/migration_helpers/README.markdown → vendor/migration_helpers/README.markdown
File renamed without changes
View
0  lib/migration_helpers/init.rb → vendor/migration_helpers/init.rb
File renamed without changes
View
0  ...migration_helpers/lib/migration_helper.rb → ...migration_helpers/lib/migration_helper.rb
File renamed without changes
Please sign in to comment.
Something went wrong with that request. Please try again.