standalone_migrations 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/standalone_migrations.gemspec +4 -4
- data/tasks/standalone_migrations.rake +41 -32
- metadata +5 -4
data/README.markdown
CHANGED
@@ -65,5 +65,5 @@ Contributors
|
|
65
65
|
This work is based on [Lincoln Stoll's blog post](http://lstoll.net/2008/04/stand-alone-activerecord-migrations/) and [David Welton's post](http://journal.dedasys.com/2007/01/28/using-migrations-outside-of-rails).
|
66
66
|
|
67
67
|
- [Todd Huss](http://gabrito.com/)
|
68
|
+
- [Michael Grosser](http://pragmatig.wordpress.com)
|
68
69
|
- [Steve Hodgkiss](http://stevehodgkiss.com/)`s [activerecord-migrator-standalone](http://github.com/stevehodgkiss/activerecord-migrator-standalone)
|
69
|
-
- [Michael Grosser](http://pragmatig.wordpress.com)
|
data/Rakefile
CHANGED
@@ -6,13 +6,13 @@ begin
|
|
6
6
|
Jeweler::Tasks.new do |gem|
|
7
7
|
gem.name = 'standalone_migrations'
|
8
8
|
gem.summary = "A thin wrapper to use Rails Migrations in non Rails projects"
|
9
|
-
gem.email = "
|
9
|
+
gem.email = "thuss@gabrito.com"
|
10
10
|
gem.homepage = "http://github.com/thuss/standalone-migrations"
|
11
|
-
gem.authors = ["Michael Grosser"]
|
11
|
+
gem.authors = ["Todd Huss", "Michael Grosser"]
|
12
12
|
%w[rake activerecord].each{|d| gem.add_dependency d}
|
13
13
|
end
|
14
14
|
|
15
15
|
Jeweler::GemcutterTasks.new
|
16
16
|
rescue LoadError
|
17
17
|
puts "Jeweler, or one of its dependencies, is not available. Install it with: sudo gem install jeweler"
|
18
|
-
end
|
18
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -5,12 +5,12 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{standalone_migrations}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Michael Grosser"]
|
12
|
-
s.date = %q{2010-03-
|
13
|
-
s.email = %q{
|
11
|
+
s.authors = ["Todd Huss", "Michael Grosser"]
|
12
|
+
s.date = %q{2010-03-18}
|
13
|
+
s.email = %q{thuss@gabrito.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"README.markdown"
|
16
16
|
]
|
@@ -1,43 +1,50 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# This file should stay copy-pasteable, so do not depend on StandaloneMigrations
|
2
|
+
# Every important option can be overwritten with MIGRATION_OPTIONS
|
3
|
+
base = File.expand_path('.')
|
4
|
+
here = File.expand_path(File.dirname(File.dirname(__FILE__)))
|
5
|
+
|
6
|
+
options = {
|
7
|
+
:base => base,
|
8
|
+
:vendor => "#{here}/vendor",
|
9
|
+
:migrations => "#{base}/db/migrations",
|
10
|
+
:config => "#{base}/db/config.yml",
|
11
|
+
:schema => "#{base}/db/schema.rb",
|
12
|
+
:env => 'DB',
|
13
|
+
:default_env => 'development'
|
14
|
+
}
|
15
|
+
options = options.merge(MIGRATION_OPTIONS) if defined?(MIGRATION_OPTIONS)
|
3
16
|
|
4
17
|
# Add to load_path every "lib/" directory in vendor
|
5
|
-
Dir["#{
|
18
|
+
Dir["#{options[:vendor]}/**/lib"].each{|p| $LOAD_PATH << p }
|
6
19
|
|
7
20
|
namespace :db do
|
8
21
|
task :ar_init do
|
9
22
|
require 'active_record'
|
10
|
-
ENV[
|
11
|
-
config = YAML.load_file(
|
23
|
+
ENV[options[:env]] ||= options[:default_env]
|
24
|
+
config = YAML.load_file(options[:config])[ENV[options[:env]]]
|
12
25
|
ActiveRecord::Base.establish_connection(config)
|
13
26
|
logger = Logger.new $stderr
|
14
27
|
logger.level = Logger::INFO
|
15
28
|
ActiveRecord::Base.logger = logger
|
16
29
|
end
|
17
30
|
|
18
|
-
desc "Migrate the database using the scripts in the
|
31
|
+
desc "Migrate the database using the scripts in the migrations directory. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
|
19
32
|
task :migrate => :ar_init do
|
20
|
-
require "#{
|
21
|
-
ActiveRecord::Migration.verbose = ENV["VERBOSE"]
|
22
|
-
ActiveRecord::Migrator.migrate(
|
23
|
-
Rake::Task[
|
33
|
+
require "#{options[:vendor]}/migration_helpers/init"
|
34
|
+
ActiveRecord::Migration.verbose = (ENV["VERBOSE"] == "true")
|
35
|
+
ActiveRecord::Migrator.migrate(options[:migrations], ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
36
|
+
Rake::Task["db:schema:dump"].execute
|
24
37
|
end
|
25
38
|
|
26
39
|
namespace :migrate do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
desc 'Runs the "down" for a given migration VERSION.'
|
36
|
-
task :down => :ar_init do
|
37
|
-
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
38
|
-
raise "VERSION is required" unless version
|
39
|
-
ActiveRecord::Migrator.run(:down, MIGRATIONS_DIR, version)
|
40
|
-
Rake::Task["db:schema:dump"].execute
|
40
|
+
[:up, :down].each do |direction|
|
41
|
+
desc "Runs the '#{direction}' for a given migration VERSION."
|
42
|
+
task direction => :ar_init do
|
43
|
+
version = (ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
44
|
+
raise "VERSION is required" unless version
|
45
|
+
ActiveRecord::Migrator.run(direction, MIGRATIONS_DIR, version)
|
46
|
+
Rake::Task["db:schema:dump"].execute
|
47
|
+
end
|
41
48
|
end
|
42
49
|
end
|
43
50
|
|
@@ -45,14 +52,14 @@ namespace :db do
|
|
45
52
|
desc "Create schema.rb file that can be portably used against any DB supported by AR"
|
46
53
|
task :dump => :ar_init do
|
47
54
|
require 'active_record/schema_dumper'
|
48
|
-
File.open(ENV['SCHEMA'] ||
|
55
|
+
File.open(ENV['SCHEMA'] || options[:schema], "w") do |file|
|
49
56
|
ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
|
50
57
|
end
|
51
58
|
end
|
52
59
|
|
53
60
|
desc "Load a ar_schema.rb file into the database"
|
54
61
|
task :load => :ar_init do
|
55
|
-
file = ENV['SCHEMA'] ||
|
62
|
+
file = ENV['SCHEMA'] || options[:schema]
|
56
63
|
load(file)
|
57
64
|
end
|
58
65
|
end
|
@@ -65,7 +72,7 @@ namespace :db do
|
|
65
72
|
exit 1
|
66
73
|
end
|
67
74
|
|
68
|
-
underscore = lambda
|
75
|
+
underscore = lambda{|camel_cased_word|
|
69
76
|
camel_cased_word.to_s.gsub(/::/, '/').
|
70
77
|
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
71
78
|
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
@@ -73,10 +80,7 @@ namespace :db do
|
|
73
80
|
downcase
|
74
81
|
}
|
75
82
|
|
76
|
-
|
77
|
-
file_name = "migrations/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration}.rb"
|
78
|
-
class_name = migration.split('_').map { |s| s.capitalize }.join
|
79
|
-
|
83
|
+
class_name = migration.split('_').map{|s| s.capitalize }.join
|
80
84
|
file_contents = <<eof
|
81
85
|
class #{class_name} < ActiveRecord::Migration
|
82
86
|
def self.up
|
@@ -87,7 +91,12 @@ class #{class_name} < ActiveRecord::Migration
|
|
87
91
|
end
|
88
92
|
end
|
89
93
|
eof
|
90
|
-
|
94
|
+
|
95
|
+
migration = underscore.call( ENV['name'] )
|
96
|
+
FileUtils.mkdir_p(options[:migrations]) unless File.exist?(options[:migrations])
|
97
|
+
file_name = "#{options[:migrations]}/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{migration}.rb"
|
98
|
+
|
99
|
+
File.open(file_name, 'w'){|f| f.write file_contents }
|
91
100
|
|
92
101
|
puts "Created migration #{file_name}"
|
93
102
|
end
|
metadata
CHANGED
@@ -4,17 +4,18 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 1
|
8
7
|
- 2
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
|
+
- Todd Huss
|
12
13
|
- Michael Grosser
|
13
14
|
autorequire:
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-03-
|
18
|
+
date: 2010-03-18 00:00:00 +01:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -42,7 +43,7 @@ dependencies:
|
|
42
43
|
type: :runtime
|
43
44
|
version_requirements: *id002
|
44
45
|
description:
|
45
|
-
email:
|
46
|
+
email: thuss@gabrito.com
|
46
47
|
executables: []
|
47
48
|
|
48
49
|
extensions: []
|