standalone_migrations_new 7.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +29 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +273 -0
  7. data/Rakefile +52 -0
  8. data/VERSION +1 -0
  9. data/example/.gitignore +5 -0
  10. data/example/Rakefile +9 -0
  11. data/example/db/config.yml +15 -0
  12. data/example/db/migrate/20120930053225_create_table_awesome_migration.rb +7 -0
  13. data/lib/standalone_migrations_new/callbacks.rb +13 -0
  14. data/lib/standalone_migrations_new/configurator.rb +103 -0
  15. data/lib/standalone_migrations_new/generator.rb +22 -0
  16. data/lib/standalone_migrations_new/minimal_railtie_config.rb +10 -0
  17. data/lib/standalone_migrations_new/tasks/connection.rake +8 -0
  18. data/lib/standalone_migrations_new/tasks/db/new_migration.rake +19 -0
  19. data/lib/standalone_migrations_new/tasks/environment.rake +3 -0
  20. data/lib/standalone_migrations_new/tasks.rb +34 -0
  21. data/lib/standalone_migrations_new.rb +20 -0
  22. data/lib/tasks/standalone_migrations_new.rb +10 -0
  23. data/spec/spec_helper.rb +4 -0
  24. data/spec/standalone_migrations_new/callbacks_spec.rb +48 -0
  25. data/spec/standalone_migrations_new/configurator_spec.rb +261 -0
  26. data/spec/standalone_migrations_new_spec.rb +371 -0
  27. data/standalone_migrations-7.1.1.gem +0 -0
  28. data/standalone_migrations_new-7.1.1.gem +0 -0
  29. data/standalone_migrations_new.gemspec +73 -0
  30. data/vendor/migration_helpers/MIT-LICENSE +20 -0
  31. data/vendor/migration_helpers/README.markdown +92 -0
  32. data/vendor/migration_helpers/init.rb +4 -0
  33. data/vendor/migration_helpers/lib/migration_helper.rb +51 -0
  34. metadata +136 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9617382dbe059140ec1110d79ee922bef72a06fef95f643dcff835019203764
4
+ data.tar.gz: 20b48fb9067cfb340d501f6d807a25b02fa1721a590e492447cbe1aa4824d0cc
5
+ SHA512:
6
+ metadata.gz: 29a2f7f54518a0b4c7bb35ec968e553d545fa3638190874ed824dc5d97049c8e9171ad2cd39060983b082d93343d0a8d81e671636cf05f1e8f5d864047792f5e
7
+ data.tar.gz: 604ea9855761bdc26db113f36f28d4737ed93b7819ac725a79cf2312e869ae7003e73b6610746888d02691a9a029f57c69d97f9f4e9a218ed8e5766090e5f4e2
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --profile
data/.travis.yml ADDED
@@ -0,0 +1,29 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.5.9
4
+ - 2.6.9
5
+ - 2.7.5
6
+ - 3.0.3
7
+ env:
8
+ - AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
9
+ - AR="~> 5.0.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
10
+ - AR=">= 5.1.0.rc2,< 5.2" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
11
+ - AR=">= 5.2.0.rc2,< 5.3,!= 5.2.3,!=5.2.3.rc1" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
12
+ - AR="~> 6.0.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
13
+ - AR="~> 6.1.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
14
+ - AR="~> 7.0.0" SQL="~>1.4" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
15
+ jobs:
16
+ exclude:
17
+ - rvm: 2.6.9
18
+ env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
19
+ - rvm: 2.7.5
20
+ env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
21
+ - rvm: 3.0.3
22
+ env: AR="~> 4.2.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
23
+ - rvm: 2.7.5
24
+ env: AR="~> 5.0.0" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
25
+ - rvm: 2.7.5
26
+ env: AR=">= 5.1.0.rc2,< 5.2" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
27
+ - rvm: 2.7.5
28
+ env: AR=">= 5.2.0.rc2,< 5.3,!= 5.2.3,!=5.2.3.rc1" SQL="~>1.3.6" NOKOGIRI_USE_SYSTEM_LIBRARIES=1
29
+ script: bundle exec rake specs:travis
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake', '~> 13.0', '>= 13.0.6'
4
+ gem 'activerecord', '~> 7.0', '>= 7.0.2.4'
5
+ gem 'railties', '~> 7.0', '>= 7.0.2.4'
6
+
7
+ group :dev do
8
+ gem 'sqlite3', '~> 1.4', '>= 1.4.2'
9
+ gem 'rspec', '~> 3.11'
10
+ gem 'jeweler', '~> 2.3', '>= 2.3.9'
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008-2016 Todd Huss
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,273 @@
1
+ Rails migrations in non-Rails (and non Ruby) projects.
2
+
3
+ [![Build Status](https://travis-ci.org/thuss/standalone-migrations.svg?branch=master)](https://travis-ci.org/thuss/standalone-migrations)
4
+
5
+ WHAT'S NEW
6
+ ==========
7
+ In the 6.x release we've added support for Rails 6 migrations thanks to [Marco Adkins](https://github.com/marcoadkins).
8
+
9
+ In the 5.x release we have moved to using Rails 5 migrations instead of maintaining our own migration related code. Just about anything you can do with Rails 5 migrations you can now do with [Standalone Migrations](https://github.com/thuss/standalone-migrations) too!
10
+
11
+ CONTRIBUTE
12
+ ==========
13
+ [Standalone Migrations](https://github.com/thuss/standalone-migrations) relies on the contributions of the open-source community! To submit a fix or an enhancement fork the repository, make your changes, add your name to the *Contributors* section in README.markdown, and send us a pull request! If you're active and do good work we'll add you as a collaborator!
14
+
15
+ USAGE
16
+ =====
17
+ Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql` or `gem install mysql2`) then:
18
+
19
+ $ gem install standalone_migrations_new
20
+
21
+ Add to `Rakefile` in your projects base directory:
22
+
23
+ ```ruby
24
+ require 'standalone_migrations_new'
25
+ StandaloneMigrationsNew::Tasks.load_tasks
26
+ ```
27
+
28
+ Add database configuration to `db/config.yml` in your projects base directory e.g.:
29
+
30
+ development:
31
+ adapter: sqlite3
32
+ database: db/development.sqlite3
33
+ pool: 5
34
+ timeout: 5000
35
+
36
+ production:
37
+ adapter: mysql
38
+ encoding: utf8
39
+ reconnect: false
40
+ database: somedatabase_dev
41
+ pool: 5
42
+ username: root
43
+ password:
44
+ socket: /var/run/mysqld/mysqld.sock
45
+
46
+ test: &test
47
+ adapter: sqlite3
48
+ database: db/test.sqlite3
49
+ pool: 5
50
+ timeout: 5000
51
+
52
+ ### To create a new database migration:
53
+
54
+ rake db:new_migration name=foo_bar_migration
55
+ edit db/migrate/20081220234130_foo_bar_migration.rb
56
+
57
+ #### If you really want to, you can just execute raw SQL:
58
+
59
+ ```ruby
60
+ def up
61
+ execute "insert into foo values (123,'something');"
62
+ end
63
+
64
+ def down
65
+ execute "delete from foo where field='something';"
66
+ end
67
+ ```
68
+
69
+ ### To apply your newest migration:
70
+
71
+ rake db:migrate
72
+
73
+ ### To migrate to a specific version (for example to rollback)
74
+
75
+ rake db:migrate VERSION=20081220234130
76
+
77
+ ### To migrate a specific database (for example your "testing" database)
78
+
79
+ rake db:migrate RAILS_ENV=test
80
+
81
+ ### To execute a specific up/down of one single migration
82
+
83
+ rake db:migrate:up VERSION=20081220234130
84
+
85
+ ### To revert your last migration
86
+
87
+ rake db:rollback
88
+
89
+ ### To revert your last 3 migrations
90
+
91
+ rake db:rollback STEP=3
92
+
93
+ ### Custom configuration
94
+
95
+ By default, Standalone Migrations will assume there exists a "db/"
96
+ directory in your project. But if for some reason you need a specific
97
+ directory structure to work with, you can use a configuration file
98
+ named .standalone_migrations_new in the root of your project containing
99
+ the following:
100
+
101
+ ```yaml
102
+ db:
103
+ seeds: db/seeds.rb
104
+ migrate: db/migrate
105
+ schema: db/schema.rb
106
+ config:
107
+ database: db/config.yml
108
+ ```
109
+
110
+ These are the configurable options available. You can omit any of
111
+ the keys and Standalone Migrations will assume the default values.
112
+
113
+ ### on_loaded callbacks
114
+
115
+ If you would like to use an external library such as [foreigner](https://github.com/matthuhiggins/foreigner) with standalone migrations, you can add the following to your `Rakefile`:
116
+
117
+ ```ruby
118
+ require 'foreigner'
119
+
120
+ StandaloneMigrationsNew.on_loaded do
121
+ Foreigner.load
122
+ end
123
+ ```
124
+
125
+ ### Multiple database support
126
+
127
+ #### Structure
128
+
129
+ Create a custom configuration file for each database and name them `.database_name.standalone_migrations_new`. The same conditions apply as described under Custom Configuration, however you are most likely want to specify all options to avoid conflicts and errors.
130
+
131
+ An example set up would look like this:
132
+
133
+ ```
134
+ app/
135
+ |-- db/
136
+ | |-- migrate/
137
+ | | |-- db1/
138
+ | | | |-- 001_migration.rb
139
+ | | |
140
+ | | |-- db2/
141
+ | | |-- 001_migration.rb
142
+ | |
143
+ | |-- config_db1.yml
144
+ | |-- config_db2.yml
145
+ | |-- seeds_db1.rb
146
+ | |-- seeds_db2.rb
147
+ | |-- schema_db1.rb
148
+ | |-- schema_db2.rb
149
+ |
150
+ |-- .db1.standalone_migrations_new
151
+ |-- .db2.standalone_migrations_new
152
+ ```
153
+ Sample config file:
154
+
155
+ ```yaml
156
+ db:
157
+ seeds: db/seeds_db1.rb
158
+ migrate: db/migrate/db1
159
+ schema: db/schema_db1.rb
160
+ config:
161
+ database: db/config_db1.yml
162
+ ```
163
+ Of course you can achieve a different layout by simply editing the paths.
164
+
165
+ ##### Running
166
+
167
+ You can run the Rake tasks on a particular database by passing the `DATABASE` environment variable to it:
168
+
169
+ $ rake db:version DATABASE=db1
170
+
171
+ Combined with the environment selector:
172
+
173
+ $ rake db:migrate DATABASE=db2 RAILS_ENV=production
174
+
175
+ #### Changing environment config in runtime
176
+
177
+ If you are using Heroku or have to create or change your connection
178
+ configuration based on runtime aspects (maybe environment variables),
179
+ you can use the `StandaloneMigrationsNew::Configurator.environments_config`
180
+ method. Check the usage example:
181
+
182
+ ```ruby
183
+ require 'tasks/standalone_migrations_new'
184
+
185
+ StandaloneMigrationsNew::Configurator.environments_config do |env|
186
+
187
+ env.on "production" do
188
+
189
+ if (ENV['DATABASE_URL'])
190
+ db = URI.parse(ENV['DATABASE_URL'])
191
+ return {
192
+ :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
193
+ :host => db.host,
194
+ :username => db.user,
195
+ :password => db.password,
196
+ :database => db.path[1..-1],
197
+ :encoding => 'utf8'
198
+ }
199
+ end
200
+
201
+ nil
202
+ end
203
+
204
+ end
205
+ ```
206
+
207
+ You have to put this anywhere on your `Rakefile`. If you want to
208
+ change some configuration, call the #on method on the object
209
+ received as argument in your block passed to ::environments_config
210
+ method call. The #on method receives the key to the configuration
211
+ that you want to change within the block. The block should return
212
+ your new configuration hash or nil if you want the configuration
213
+ to stay the same.
214
+
215
+ Your logic to decide the new configuration need to access some data
216
+ in your current configuration? Then you should receive the configuration
217
+ in your block, like this:
218
+
219
+ ```ruby
220
+ require 'tasks/standalone_migrations_new'
221
+
222
+ StandaloneMigrationsNew::Configurator.environments_config do |env|
223
+
224
+ env.on "my_custom_config" do |current_custom_config|
225
+ p current_custom_config
226
+ # => the values on your current "my_custom_config" environment
227
+ nil
228
+ end
229
+
230
+ end
231
+ ```
232
+
233
+ #### Exporting Generated SQL
234
+
235
+ If instead of the database-agnostic `schema.rb` file you'd like to
236
+ save the database-specific SQL generated by the migrations, simply
237
+ add this to your `Rakefile`.
238
+
239
+ ```ruby
240
+ require 'tasks/standalone_migrations_new'
241
+ ActiveRecord::Base.schema_format = :sql
242
+ ```
243
+
244
+ You should see a `db/structure.sql` file the next time you run a
245
+ migration.
246
+
247
+ Contributors
248
+ ============
249
+ - [Todd Huss](http://gabrito.com/)
250
+ - [Michael Grosser](http://pragmatig.wordpress.com)
251
+ - [Ricardo Valeriano](http://ricardovaleriano.com/)
252
+ - [Two Bit Labs](http://twobitlabs.com/)
253
+ - [Windandtides](http://windandtides.com/)
254
+ - [Eric Lindvall](http://bitmonkey.net)
255
+ - [Steve Hodgkiss](http://stevehodgkiss.com/)
256
+ - [Rich Meyers](https://github.com/richmeyers)
257
+ - [Wes Bailey](http://exposinggotchas.blogspot.com/)
258
+ - [Robert J. Berger](http://blog.ibd.com/)
259
+ - [Federico Builes](http://mheroin.com/)
260
+ - [Gazler](http://blog.gazler.com/)
261
+ - [Yuu Yamashita](https://github.com/yyuu)
262
+ - [Koen Punt](http://www.koen.pt/)
263
+ - [Parker Moore](http://www.parkermoore.de/)
264
+ - [Marcell Jusztin](http://www.morcmarc.com)
265
+ - [Eric Hayes](http://ejhay.es)
266
+ - [Yi Wen](https://github.com/ywen)
267
+ - [Jonathan Rochkind](https://github.com/jrochkind)
268
+ - [Michael Mikhailov](https://github.com/yohanson)
269
+ - [Benjamin Dobell](https://github.com/Benjamin-Dobell)
270
+ - [Hassan Mahmoud](https://github.com/HassanTC)
271
+ - [Marco Adkins](https://github.com/marcoadkins)
272
+ - [Mithun James](https://github.com/drtechie)
273
+ - [Sarah Ridge](https://github.com/smridge)
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ task :default do
5
+ sh "rspec spec"
6
+ end
7
+
8
+ task :all do
9
+ sh "AR='~>3.0.0' bundle update activerecord && bundle exec rake"
10
+ sh "AR='~>3.1.0.rc4' bundle update activerecord && bundle exec rake"
11
+ end
12
+
13
+ task :specs => ["specs:nodb"]
14
+ namespace :specs do
15
+ require 'rspec/core/rake_task'
16
+
17
+ desc "only specs that don't use database connection"
18
+ RSpec::Core::RakeTask.new "nodb" do |t|
19
+ t.pattern = "spec/standalone_migrations_new/**/*_spec.rb"
20
+ end
21
+
22
+ desc "run all specs for travis"
23
+ RSpec::Core::RakeTask.new "travis" do |t|
24
+ t.pattern = "spec/**/*_spec.rb"
25
+ t.rspec_opts = "--tag ~@travis_error"
26
+ end
27
+
28
+ desc "run all specs including those which uses database"
29
+ task :all => [:default, :nodb]
30
+ end
31
+
32
+ # rake install -> install gem locally (for tests)
33
+ # rake release -> push to github and release to gemcutter
34
+ # rake version:bump:patch -> increase version and add a git-tag
35
+ begin
36
+ require 'jeweler'
37
+ rescue LoadError => e
38
+ $stderr.puts "Jeweler, or one of its dependencies, is not available:"
39
+ $stderr.puts "#{e.class}: #{e.message}"
40
+ $stderr.puts "Install it with: sudo gem install jeweler"
41
+ else
42
+ Jeweler::Tasks.new do |gem|
43
+ gem.name = 'standalone_migrations_new'
44
+ gem.summary = "A thin wrapper to use Rails Migrations in non Rails projects"
45
+ gem.email = "enotikalt@gmail.com"
46
+ gem.homepage = "https://github.com/enotikalt/standalone-migrations"
47
+ gem.authors = ["Serhii Hiba"]
48
+ gem.license = "MIT"
49
+ end
50
+
51
+ Jeweler::GemcutterTasks.new
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 7.1.0
@@ -0,0 +1,5 @@
1
+ *.sqlite3
2
+ Gemfile
3
+ .bundle/
4
+ bin/
5
+ Gemfile.lock
data/example/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # $LOAD_PATH handling not need if the standalone_migrations_new
2
+ # gem is installed
3
+ lib = File.expand_path("../../lib", __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require "standalone_migrations_new"
7
+ StandaloneMigrationsNew::Tasks.load_tasks
8
+
9
+ # and that's it!
@@ -0,0 +1,15 @@
1
+ development:
2
+ adapter: sqlite3
3
+ database: db/development.sqlite3
4
+ pool: 5
5
+ timeout: 5000
6
+ test:
7
+ adapter: sqlite3
8
+ database: db/test.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+ production:
12
+ adapter: sqlite3
13
+ database: db/production.sqlite3
14
+ pool: 5
15
+ timeout: 5000
@@ -0,0 +1,7 @@
1
+ class CreateTableAwesomeMigration < ActiveRecord::Migration[5.0]
2
+ def up
3
+ end
4
+
5
+ def down
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module StandaloneMigrationsNew
2
+ @@callbacks ||= []
3
+
4
+ def self.on_loaded(&block)
5
+ @@callbacks << block
6
+ end
7
+
8
+ def self.run_on_load_callbacks
9
+ @@callbacks.each do |callback|
10
+ callback.call
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,103 @@
1
+ require 'active_support/all'
2
+ require 'yaml'
3
+
4
+ module StandaloneMigrationsNew
5
+
6
+ class InternalConfigurationsProxy
7
+
8
+ attr_reader :configurations
9
+ def initialize(configurations)
10
+ @configurations = configurations
11
+ end
12
+
13
+ def on(config_key)
14
+ if @configurations[config_key] && block_given?
15
+ @configurations[config_key] = yield(@configurations[config_key]) || @configurations[config_key]
16
+ end
17
+ @configurations[config_key]
18
+ end
19
+
20
+ end
21
+
22
+ class Configurator
23
+ def self.load_configurations
24
+ @env_config ||= Rails.application.config.database_configuration
25
+ ActiveRecord::Base.configurations = @env_config
26
+ @env_config
27
+ end
28
+
29
+ def self.environments_config
30
+ proxy = InternalConfigurationsProxy.new(load_configurations)
31
+ yield(proxy) if block_given?
32
+ end
33
+
34
+ def initialize(options = {})
35
+ default_schema = ENV['SCHEMA'] || ActiveRecord::Tasks::DatabaseTasks.schema_file_type(ActiveRecord::Base.schema_format)
36
+ defaults = {
37
+ :config => "db/config.yml",
38
+ :migrate_dir => "db/migrate",
39
+ :root => Pathname.pwd,
40
+ :seeds => "db/seeds.rb",
41
+ :schema => default_schema
42
+ }
43
+ @options = load_from_file(defaults.dup) || defaults.merge(options)
44
+
45
+ ENV['SCHEMA'] = schema
46
+ Rails.application.config.root = root
47
+ Rails.application.config.paths["config/database"] = config
48
+ Rails.application.config.paths["db/migrate"] = migrate_dir
49
+ Rails.application.config.paths["db/seeds.rb"] = seeds
50
+ end
51
+
52
+ def config
53
+ @options[:config]
54
+ end
55
+
56
+ def migrate_dir
57
+ @options[:migrate_dir]
58
+ end
59
+
60
+ def root
61
+ @options[:root]
62
+ end
63
+
64
+ def seeds
65
+ @options[:seeds]
66
+ end
67
+
68
+ def schema
69
+ @options[:schema]
70
+ end
71
+
72
+ def config_for_all
73
+ Configurator.load_configurations.dup
74
+ end
75
+
76
+ def config_for(environment)
77
+ config_for_all[environment.to_s]
78
+ end
79
+
80
+ private
81
+
82
+ def configuration_file
83
+ if !ENV['DATABASE']
84
+ ".standalone_migrations_new"
85
+ else
86
+ ".#{ENV['DATABASE']}.standalone_migrations_new"
87
+ end
88
+ end
89
+
90
+ def load_from_file(defaults)
91
+ return nil unless File.exists? configuration_file
92
+ config = YAML.load( ERB.new(IO.read(configuration_file)).result )
93
+ {
94
+ :config => config["config"] ? config["config"]["database"] : defaults[:config],
95
+ :migrate_dir => (config["db"] || {})["migrate"] || defaults[:migrate_dir],
96
+ :root => config["root"] || defaults[:root],
97
+ :seeds => (config["db"] || {})["seeds"] || defaults[:seeds],
98
+ :schema => (config["db"] || {})["schema"] || defaults[:schema]
99
+ }
100
+ end
101
+
102
+ end
103
+ end
@@ -0,0 +1,22 @@
1
+ # these generators are backed by rails' generators
2
+ require "rails/generators"
3
+ require 'rails/generators/active_record/migration/migration_generator'
4
+ module StandaloneMigrationsNew
5
+ class Generator
6
+ def self.migration(name, options="")
7
+ generator_params = [name] + options.split(" ")
8
+ Rails::Generators.invoke "active_record:migration", generator_params,
9
+ :destination_root => Rails.root
10
+ end
11
+ end
12
+
13
+ class CacheMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
14
+ source_root File.join(File.dirname(ActiveRecord::Generators::MigrationGenerator.instance_method(:create_migration_file).source_location.first), "templates")
15
+
16
+ def create_migration_file
17
+ set_local_assigns!
18
+ validate_file_name!
19
+ migration_template @migration_template, Rails.application.config.paths["db/migrate"]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,10 @@
1
+ module StandaloneMigrationsNew
2
+ class StandaloneMigrationsNew::MinimalRailtieConfig < Rails::Application
3
+ config.generators.options[:rails] = {:orm => :active_record}
4
+
5
+ config.generators.options[:active_record] = {
6
+ :migration => true,
7
+ :timestamps => true
8
+ }
9
+ end
10
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path("../../../standalone_migrations_new", __FILE__)
2
+ namespace :standalone do
3
+ task :connection do
4
+ StandaloneMigrationsNew::Configurator.load_configurations
5
+ ActiveRecord::Base.establish_connection
6
+ StandaloneMigrationsNew.run_on_load_callbacks
7
+ end
8
+ end
@@ -0,0 +1,19 @@
1
+ namespace :db do
2
+ desc "Creates a new migration file with the specified name"
3
+ task :new_migration, :name, :options do |t, args|
4
+ name = args[:name] || ENV['name']
5
+ options = args[:options] || ENV['options']
6
+
7
+ unless name
8
+ puts "Error: must provide name of migration to generate."
9
+ puts "For example: rake #{t.name} name=add_field_to_form"
10
+ abort
11
+ end
12
+
13
+ if options
14
+ StandaloneMigrationsNew::Generator.migration name, options.gsub('/', ' ')
15
+ else
16
+ StandaloneMigrationsNew::Generator.migration name
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ require File.expand_path("../../../standalone_migrations_new", __FILE__)
2
+ task :environment => ["standalone:connection"] do
3
+ end
@@ -0,0 +1,34 @@
1
+ module StandaloneMigrationsNew
2
+ class Tasks
3
+ class << self
4
+ def configure(options = {})
5
+ Deprecations.new.call
6
+ Configurator.new options
7
+ end
8
+
9
+ def load_tasks(options = {})
10
+ configure(options)
11
+ Configurator.environments_config do |proxy|
12
+ ActiveRecord::Tasks::DatabaseTasks.database_configuration = proxy.configurations
13
+ end
14
+ MinimalRailtieConfig.load_tasks
15
+ %w(
16
+ connection
17
+ environment
18
+ db/new_migration
19
+ ).each do
20
+ |task| load "standalone_migrations_new/tasks/#{task}.rake"
21
+ end
22
+ load "active_record/railties/databases.rake"
23
+ end
24
+ end
25
+ end
26
+
27
+ class Tasks::Deprecations
28
+ def call
29
+ if File.directory?('db/migrations')
30
+ puts "DEPRECATED move your migrations into db/migrate"
31
+ end
32
+ end
33
+ end
34
+ end