cairn 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ba4274ba8716f03a1e7972f778a13648d919086be778d87c6133c1afcdec8f8f
4
+ data.tar.gz: 28a9c63a1e03e0e4cc2072345e4f3779264b72aede9be03e18b51cd26eda7771
5
+ SHA512:
6
+ metadata.gz: 61a83419b8d76b5dfc9385276c3c71534d4d9e012e61ae1a3036ed4762d0cacc57cfdd07c9ddffe3e1ca20cb6048e95c24f421bf77417869f689846e18b2dd60
7
+ data.tar.gz: bff448a61ca02321758f19b3afaec6fe39ea572393d20f146f07f91281556ad6350c9d4de4a754c20398ca65da52b84bdf8855aaad16d046afcfbdb4b7b0f1ce
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', '>= 10.0'
4
+ gem 'activerecord', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
5
+ gem 'railties', ENV['AR'] ? ENV['AR'].split(",") : [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!=5.2.3.rc1"]
6
+
7
+ group :dev do
8
+ gem 'sqlite3', ENV['SQL'] ? ENV['SQL'].split(",") : ['~> 1.4']
9
+ gem 'rspec', '>= 2.99.0'
10
+ gem 'jeweler'
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,277 @@
1
+ # Cairn
2
+
3
+ Cairn is a mirror/fork of [standalone-migrations](https://github.com/thuss/standalone-migrations), which sometimes goes a while without a bug fix.
4
+
5
+ Rails migrations in non-Rails (and non Ruby) projects.
6
+
7
+ [![Build Status](https://travis-ci.org/thuss/standalone-migrations.svg?branch=master)](https://travis-ci.org/thuss/standalone-migrations)
8
+
9
+ WHAT'S NEW
10
+ ==========
11
+ In the 6.x release we've added support for Rails 6 migrations thanks to [Marco Adkins](https://github.com/marcoadkins).
12
+
13
+ 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!
14
+
15
+ CONTRIBUTE
16
+ ==========
17
+ [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!
18
+
19
+ USAGE
20
+ =====
21
+ Install Ruby, RubyGems and a ruby-database driver (e.g. `gem install mysql` or `gem install mysql2`) then:
22
+
23
+ $ gem install standalone_migrations
24
+
25
+ Add to `Rakefile` in your projects base directory:
26
+
27
+ ```ruby
28
+ require 'standalone_migrations'
29
+ StandaloneMigrations::Tasks.load_tasks
30
+ ```
31
+
32
+ Add database configuration to `db/config.yml` in your projects base directory e.g.:
33
+
34
+ development:
35
+ adapter: sqlite3
36
+ database: db/development.sqlite3
37
+ pool: 5
38
+ timeout: 5000
39
+
40
+ production:
41
+ adapter: mysql
42
+ encoding: utf8
43
+ reconnect: false
44
+ database: somedatabase_dev
45
+ pool: 5
46
+ username: root
47
+ password:
48
+ socket: /var/run/mysqld/mysqld.sock
49
+
50
+ test: &test
51
+ adapter: sqlite3
52
+ database: db/test.sqlite3
53
+ pool: 5
54
+ timeout: 5000
55
+
56
+ ### To create a new database migration:
57
+
58
+ rake db:new_migration name=foo_bar_migration
59
+ edit db/migrate/20081220234130_foo_bar_migration.rb
60
+
61
+ #### If you really want to, you can just execute raw SQL:
62
+
63
+ ```ruby
64
+ def up
65
+ execute "insert into foo values (123,'something');"
66
+ end
67
+
68
+ def down
69
+ execute "delete from foo where field='something';"
70
+ end
71
+ ```
72
+
73
+ ### To apply your newest migration:
74
+
75
+ rake db:migrate
76
+
77
+ ### To migrate to a specific version (for example to rollback)
78
+
79
+ rake db:migrate VERSION=20081220234130
80
+
81
+ ### To migrate a specific database (for example your "testing" database)
82
+
83
+ rake db:migrate RAILS_ENV=test
84
+
85
+ ### To execute a specific up/down of one single migration
86
+
87
+ rake db:migrate:up VERSION=20081220234130
88
+
89
+ ### To revert your last migration
90
+
91
+ rake db:rollback
92
+
93
+ ### To revert your last 3 migrations
94
+
95
+ rake db:rollback STEP=3
96
+
97
+ ### Custom configuration
98
+
99
+ By default, Standalone Migrations will assume there exists a "db/"
100
+ directory in your project. But if for some reason you need a specific
101
+ directory structure to work with, you can use a configuration file
102
+ named .standalone_migrations in the root of your project containing
103
+ the following:
104
+
105
+ ```yaml
106
+ db:
107
+ seeds: db/seeds.rb
108
+ migrate: db/migrate
109
+ schema: db/schema.rb
110
+ config:
111
+ database: db/config.yml
112
+ ```
113
+
114
+ These are the configurable options available. You can omit any of
115
+ the keys and Standalone Migrations will assume the default values.
116
+
117
+ ### on_loaded callbacks
118
+
119
+ 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`:
120
+
121
+ ```ruby
122
+ require 'foreigner'
123
+
124
+ StandaloneMigrations.on_loaded do
125
+ Foreigner.load
126
+ end
127
+ ```
128
+
129
+ ### Multiple database support
130
+
131
+ #### Structure
132
+
133
+ Create a custom configuration file for each database and name them `.database_name.standalone_migrations`. The same conditions apply as described under Custom Configuration, however you are most likely want to specify all options to avoid conflicts and errors.
134
+
135
+ An example set up would look like this:
136
+
137
+ ```
138
+ app/
139
+ |-- db/
140
+ | |-- migrate/
141
+ | | |-- db1/
142
+ | | | |-- 001_migration.rb
143
+ | | |
144
+ | | |-- db2/
145
+ | | |-- 001_migration.rb
146
+ | |
147
+ | |-- config_db1.yml
148
+ | |-- config_db2.yml
149
+ | |-- seeds_db1.rb
150
+ | |-- seeds_db2.rb
151
+ | |-- schema_db1.rb
152
+ | |-- schema_db2.rb
153
+ |
154
+ |-- .db1.standalone_migrations
155
+ |-- .db2.standalone_migrations
156
+ ```
157
+ Sample config file:
158
+
159
+ ```yaml
160
+ db:
161
+ seeds: db/seeds_db1.rb
162
+ migrate: db/migrate/db1
163
+ schema: db/schema_db1.rb
164
+ config:
165
+ database: db/config_db1.yml
166
+ ```
167
+ Of course you can achieve a different layout by simply editing the paths.
168
+
169
+ ##### Running
170
+
171
+ You can run the Rake tasks on a particular database by passing the `DATABASE` environment variable to it:
172
+
173
+ $ rake db:version DATABASE=db1
174
+
175
+ Combined with the environment selector:
176
+
177
+ $ rake db:migrate DATABASE=db2 RAILS_ENV=production
178
+
179
+ #### Changing environment config in runtime
180
+
181
+ If you are using Heroku or have to create or change your connection
182
+ configuration based on runtime aspects (maybe environment variables),
183
+ you can use the `StandaloneMigrations::Configurator.environments_config`
184
+ method. Check the usage example:
185
+
186
+ ```ruby
187
+ require 'tasks/standalone_migrations'
188
+
189
+ StandaloneMigrations::Configurator.environments_config do |env|
190
+
191
+ env.on "production" do
192
+
193
+ if (ENV['DATABASE_URL'])
194
+ db = URI.parse(ENV['DATABASE_URL'])
195
+ return {
196
+ :adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
197
+ :host => db.host,
198
+ :username => db.user,
199
+ :password => db.password,
200
+ :database => db.path[1..-1],
201
+ :encoding => 'utf8'
202
+ }
203
+ end
204
+
205
+ nil
206
+ end
207
+
208
+ end
209
+ ```
210
+
211
+ You have to put this anywhere on your `Rakefile`. If you want to
212
+ change some configuration, call the #on method on the object
213
+ received as argument in your block passed to ::environments_config
214
+ method call. The #on method receives the key to the configuration
215
+ that you want to change within the block. The block should return
216
+ your new configuration hash or nil if you want the configuration
217
+ to stay the same.
218
+
219
+ Your logic to decide the new configuration need to access some data
220
+ in your current configuration? Then you should receive the configuration
221
+ in your block, like this:
222
+
223
+ ```ruby
224
+ require 'tasks/standalone_migrations'
225
+
226
+ StandaloneMigrations::Configurator.environments_config do |env|
227
+
228
+ env.on "my_custom_config" do |current_custom_config|
229
+ p current_custom_config
230
+ # => the values on your current "my_custom_config" environment
231
+ nil
232
+ end
233
+
234
+ end
235
+ ```
236
+
237
+ #### Exporting Generated SQL
238
+
239
+ If instead of the database-agnostic `schema.rb` file you'd like to
240
+ save the database-specific SQL generated by the migrations, simply
241
+ add this to your `Rakefile`.
242
+
243
+ ```ruby
244
+ require 'tasks/standalone_migrations'
245
+ ActiveRecord::Base.schema_format = :sql
246
+ ```
247
+
248
+ You should see a `db/structure.sql` file the next time you run a
249
+ migration.
250
+
251
+ Contributors
252
+ ============
253
+ - [Todd Huss](http://gabrito.com/)
254
+ - [Michael Grosser](http://pragmatig.wordpress.com)
255
+ - [Ricardo Valeriano](http://ricardovaleriano.com/)
256
+ - [Two Bit Labs](http://twobitlabs.com/)
257
+ - [Windandtides](http://windandtides.com/)
258
+ - [Eric Lindvall](http://bitmonkey.net)
259
+ - [Steve Hodgkiss](http://stevehodgkiss.com/)
260
+ - [Rich Meyers](https://github.com/richmeyers)
261
+ - [Wes Bailey](http://exposinggotchas.blogspot.com/)
262
+ - [Robert J. Berger](http://blog.ibd.com/)
263
+ - [Federico Builes](http://mheroin.com/)
264
+ - [Gazler](http://blog.gazler.com/)
265
+ - [Yuu Yamashita](https://github.com/yyuu)
266
+ - [Koen Punt](http://www.koen.pt/)
267
+ - [Parker Moore](http://www.parkermoore.de/)
268
+ - [Marcell Jusztin](http://www.morcmarc.com)
269
+ - [Eric Hayes](http://ejhay.es)
270
+ - [Yi Wen](https://github.com/ywen)
271
+ - [Jonathan Rochkind](https://github.com/jrochkind)
272
+ - [Michael Mikhailov](https://github.com/yohanson)
273
+ - [Benjamin Dobell](https://github.com/Benjamin-Dobell)
274
+ - [Hassan Mahmoud](https://github.com/HassanTC)
275
+ - [Marco Adkins](https://github.com/marcoadkins)
276
+ - [Mithun James](https://github.com/drtechie)
277
+ - [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/**/*_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 = 'cairn'
44
+ gem.summary = "A thin wrapper to use Rails Migrations in non Rails projects"
45
+ gem.email = "me@kow.fm"
46
+ gem.homepage = "http://github.com/karloscarweber/cairn"
47
+ gem.authors = ["Karl Oscar Weber"]
48
+ gem.license = "MIT"
49
+ end
50
+
51
+ Jeweler::GemcutterTasks.new
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 7.1.0
data/cairn.gemspec ADDED
@@ -0,0 +1,71 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: cairn 7.1.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "cairn".freeze
9
+ s.version = "7.1.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
+ s.require_paths = ["lib".freeze]
13
+ s.authors = ["Karl Oscar Weber".freeze]
14
+ s.date = "2022-08-26"
15
+ s.email = "me@kow.fm".freeze
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.markdown"
19
+ ]
20
+ s.files = [
21
+ ".rspec",
22
+ ".travis.yml",
23
+ "Gemfile",
24
+ "LICENSE",
25
+ "README.markdown",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "cairn.gemspec",
29
+ "example/.gitignore",
30
+ "example/Rakefile",
31
+ "example/db/config.yml",
32
+ "example/db/migrate/20120930053225_create_table_awesome_migration.rb",
33
+ "lib/standalone_migrations.rb",
34
+ "lib/standalone_migrations/callbacks.rb",
35
+ "lib/standalone_migrations/configurator.rb",
36
+ "lib/standalone_migrations/generator.rb",
37
+ "lib/standalone_migrations/minimal_railtie_config.rb",
38
+ "lib/standalone_migrations/tasks.rb",
39
+ "lib/standalone_migrations/tasks/connection.rake",
40
+ "lib/standalone_migrations/tasks/db/new_migration.rake",
41
+ "lib/standalone_migrations/tasks/environment.rake",
42
+ "lib/tasks/standalone_migrations.rb",
43
+ "spec/spec_helper.rb",
44
+ "spec/standalone_migrations/callbacks_spec.rb",
45
+ "spec/standalone_migrations/configurator_spec.rb",
46
+ "spec/standalone_migrations_spec.rb",
47
+ "vendor/migration_helpers/MIT-LICENSE",
48
+ "vendor/migration_helpers/README.markdown",
49
+ "vendor/migration_helpers/init.rb",
50
+ "vendor/migration_helpers/lib/migration_helper.rb"
51
+ ]
52
+ s.homepage = "http://github.com/karloscarweber/cairn".freeze
53
+ s.licenses = ["MIT".freeze]
54
+ s.rubygems_version = "3.3.7".freeze
55
+ s.summary = "A thin wrapper to use Rails Migrations in non Rails projects".freeze
56
+
57
+ if s.respond_to? :specification_version then
58
+ s.specification_version = 4
59
+ end
60
+
61
+ if s.respond_to? :add_runtime_dependency then
62
+ s.add_runtime_dependency(%q<rake>.freeze, [">= 10.0"])
63
+ s.add_runtime_dependency(%q<activerecord>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
64
+ s.add_runtime_dependency(%q<railties>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
65
+ else
66
+ s.add_dependency(%q<rake>.freeze, [">= 10.0"])
67
+ s.add_dependency(%q<activerecord>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
68
+ s.add_dependency(%q<railties>.freeze, [">= 4.2.7", "< 7.1.0", "!= 5.2.3", "!= 5.2.3.rc1"])
69
+ end
70
+ end
71
+
@@ -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
2
+ # gem is installed
3
+ lib = File.expand_path("../../lib", __FILE__)
4
+ $:.unshift lib unless $:.include?(lib)
5
+
6
+ require "standalone_migrations"
7
+ StandaloneMigrations::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 StandaloneMigrations
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 StandaloneMigrations
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'] || "db/schema.rb"
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"
85
+ else
86
+ ".#{ENV['DATABASE']}.standalone_migrations"
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 StandaloneMigrations
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 StandaloneMigrations
2
+ class StandaloneMigrations::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", __FILE__)
2
+ namespace :standalone do
3
+ task :connection do
4
+ StandaloneMigrations::Configurator.load_configurations
5
+ ActiveRecord::Base.establish_connection
6
+ StandaloneMigrations.run_on_load_callbacks
7
+ end
8
+ end