standalone_migrations 2.0.6 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -107,6 +107,56 @@ config:
107
107
  These are the configurable options available. You can omit any of
108
108
  the keys and Standalone Migrations will assume the default values.
109
109
 
110
+ ###Multiple database support
111
+
112
+ ####Structure
113
+
114
+ 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.
115
+
116
+ An example set up would look like this:
117
+
118
+ ```
119
+ app/
120
+ |-- db/
121
+ | |-- migrate/
122
+ | | |-- db1/
123
+ | | | |-- 001_migration.rb
124
+ | | |
125
+ | | |-- db2/
126
+ | | |-- 001_migration.rb
127
+ | |
128
+ | |-- config_db1.yml
129
+ | |-- config_db2.yml
130
+ | |-- seeds_db1.rb
131
+ | |-- seeds_db2.rb
132
+ | |-- schema_db1.rb
133
+ | |-- schema_db2.rb
134
+ |
135
+ |-- .db1.standalone_migrations
136
+ |-- .db2.standalone_migrations
137
+ ```
138
+ Sample config file:
139
+
140
+ ```yaml
141
+ db:
142
+ seeds: db/seeds_db1.rb
143
+ migrate: db/migrate/db1
144
+ schema: db/schema_db1.rb
145
+ config:
146
+ database: db/config_db1.yml
147
+ ```
148
+ Of course you can achieve a different layout by simply editing the paths.
149
+
150
+ #####Running
151
+
152
+ You can run the Rake tasks on a particular database by passing the `DATABASE` environment variable to it:
153
+
154
+ $ rake DATABASE=db1 db:version
155
+
156
+ Combined with the environment selector:
157
+
158
+ $ rake DATABASE=db2 DB=production db:migrate
159
+
110
160
  #### Changing environment config in runtime
111
161
 
112
162
  If you are using Heroku or have to create or change your connection
@@ -197,5 +247,6 @@ Contributors
197
247
  - [Yuu Yamashita](https://github.com/yyuu)
198
248
  - [Koen Punt](http://www.koen.pt/)
199
249
  - [Parker Moore](http://www.parkermoore.de/)
250
+ - [Marcell Jusztin](http://www.morcmarc.com)
200
251
 
201
252
  This work is originally 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).
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.6
1
+ 2.1.0
@@ -66,7 +66,11 @@ module StandaloneMigrations
66
66
  private
67
67
 
68
68
  def configuration_file
69
- ".standalone_migrations"
69
+ if !ENV['DATABASE']
70
+ ".standalone_migrations"
71
+ else
72
+ ".#{ENV['DATABASE']}.standalone_migrations"
73
+ end
70
74
  end
71
75
 
72
76
  def load_from_file(defaults)
@@ -14,6 +14,14 @@ module StandaloneMigrations
14
14
  }
15
15
  end
16
16
 
17
+ let(:env_hash_other_db) do
18
+ {
19
+ "development" => { "adapter" => "mysql2", "database" => "database_name" },
20
+ "test" => { "adapter" => "mysql2", "database" => "database_name" },
21
+ "production" => {"adapter" => "mysql2", "database" => "database_name" }
22
+ }
23
+ end
24
+
17
25
  before(:all) do
18
26
  @original_dir = Dir.pwd
19
27
  Dir.chdir( File.expand_path("../../", __FILE__) )
@@ -156,13 +164,52 @@ module StandaloneMigrations
156
164
  }
157
165
  end
158
166
 
167
+ let(:yaml_hash_other_db) do
168
+ {
169
+ "db" => {
170
+ "seeds" => "db2/seeds.rb",
171
+ "migrate" => "db2/migrate",
172
+ "schema" => "db2/schema.rb"
173
+ },
174
+ "config" => {
175
+ "database" => "config/config_other.yml"
176
+ }
177
+ }
178
+ end
179
+
159
180
  let(:configurator) do
160
181
  file = ".standalone_migrations"
161
182
  File.open(file, "w") { |file| file.write(yaml_hash.to_yaml) }
162
-
163
183
  Configurator.new
164
184
  end
165
185
 
186
+ context "with database environment variable passed" do
187
+
188
+ before(:all) do
189
+ ENV['DATABASE'] = "other_db"
190
+ end
191
+
192
+ let(:other_configurator) do
193
+ file_other_db = ".other_db.standalone_migrations"
194
+ File.open(file_other_db, "w") { |file| file.write(yaml_hash_other_db.to_yaml) }
195
+ Configurator.new
196
+ end
197
+
198
+ it "look up named dot file" do
199
+ other_configurator.config.should == yaml_hash_other_db['config']['database']
200
+ end
201
+
202
+ it "load config from named dot file" do
203
+ other_configurator.migrate_dir.should == 'db2/migrate'
204
+ end
205
+
206
+ after(:all) do
207
+ File.delete ".other_db.standalone_migrations"
208
+ ENV['DATABASE'] = nil
209
+ end
210
+
211
+ end
212
+
166
213
  context "with some configurations missing" do
167
214
 
168
215
  let(:yaml_hash) do
@@ -180,6 +227,7 @@ module StandaloneMigrations
180
227
  it "use custom config from file" do
181
228
  configurator.config.should == yaml_hash["config"]["database"]
182
229
  end
230
+
183
231
  end
184
232
 
185
233
  it "use custom config from file" do
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "standalone_migrations"
8
- s.version = "2.0.6"
8
+ s.version = "2.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Todd Huss", "Michael Grosser"]
12
- s.date = "2013-03-19"
12
+ s.date = "2013-04-04"
13
13
  s.email = "thuss@gabrito.com"
14
14
  s.extra_rdoc_files = [
15
15
  "README.markdown"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standalone_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-03-19 00:00:00.000000000 Z
13
+ date: 2013-04-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -109,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  segments:
111
111
  - 0
112
- hash: 2619405077468611021
112
+ hash: 3953024186971658303
113
113
  required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  none: false
115
115
  requirements: