multi-database-9000 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/features/running_generators.feature +12 -0
- data/lib/generators/multi_migration_generator.rb +17 -11
- data/lib/multi-database-9000/version.rb +1 -1
- data/multi-db-dummy/Gemfile.lock +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1e52410b94cd1ebbf0ba4bff0d6454877eb3089
|
4
|
+
data.tar.gz: c8acc0fbde4701940948b4cfde04da7c46a17c99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 386f8b2b90cda2dffe2775e08c512317459a1661e6e2ad77609f2fe21555fa27936e8510dce32bd5a76ae56c00a3d8fdd3ef700541463c4f6e27e7aa0a107b8b
|
7
|
+
data.tar.gz: 819a923c069d2d92e2596a8cacf8e21fd050914f503d5872dd885c2422c885c4a8ba5ae0d055b32c4a5e9c66a08ea3bcb72f62a4ce2521bd5dd270e01e0e9846
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -39,7 +39,7 @@ Create a new set of connections for your database in database.yml, in the form o
|
|
39
39
|
Create a new directory under db/ called *database_name*_migrate to hold migrations for the database.
|
40
40
|
|
41
41
|
### The Multi Migration command
|
42
|
-
Create a new migration with "rails generate multi_migration *migration* *database_name*". The *database_name* is 'default' for your default or original database, otherwise it is the name of the database you wish to migrate to e.g. "rails generate multi_migration AddTitleToWidgets widgets".
|
42
|
+
Create a new migration with "rails generate multi_migration *migration* *database_name*". The *database_name* is 'default' for your default or original database (this can also be left off for the default database only and the migration will still work), otherwise it is the name of the database you wish to migrate to e.g. "rails generate multi_migration AddTitleToWidgets widgets".
|
43
43
|
|
44
44
|
If you wish to use multi-database-9000 in a single database app, the command 'rails generate migration CreateWidgetsTable' will still work.
|
45
45
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
Feature: Running rails generate commands produces migration files in the correct database migration folders
|
2
2
|
|
3
3
|
'rails generate migration CreateXxxxxTable' should create a migration file in the 'migrate' folder in a single database app
|
4
|
+
'rails generate multi_migration CreateXxxxxTable' should create a migration file in the 'migrate' folder in a multi-database app
|
4
5
|
'rails generate multi_migration CreateXxxxxTable default' should create a migration file in the 'migrate' folder in a multi-database app
|
5
6
|
'rails generate multi_migration CreateXxxxxTable users' should create a migration file in the 'users_migrate' folder in a multi-database app
|
6
7
|
'rails generate multi_migration CreateXxxxxTable widgets' should create a migration file in the 'widgets_migrate' folder in a multi-database app
|
@@ -14,10 +15,21 @@ Feature: Running rails generate commands produces migration files in the correct
|
|
14
15
|
Then I should see the db/migrate folder in a single database app
|
15
16
|
And I should see a migration file in the db/migrate folder in a single database app
|
16
17
|
|
18
|
+
Scenario: Running 'rails generate migration' in a multi database app
|
19
|
+
Given There are no migration folders before a migration is generated in a multi database app
|
20
|
+
And I run `rails generate migration CreateFoolsTable` in a multi database app
|
21
|
+
Then I should see the db/migrate folder for the default database
|
22
|
+
|
23
|
+
Scenario: Running 'rails generate multi_migration' in a multi database app
|
24
|
+
Given There are no migration folders before a migration is generated in a multi database app
|
25
|
+
And I run `rails generate multi_migration CreateFoolsTable` in a multi database app
|
26
|
+
Then I should see the db/migrate folder for the default database
|
27
|
+
|
17
28
|
Scenario: Running "rails generate multi_migration <database_name>" in a multi database app
|
18
29
|
Given There are no migration folders before a migration is generated in a multi database app
|
19
30
|
And I run `rails generate multi_migration CreateFoolsTable default` in a multi database app
|
20
31
|
Then I should see the db/migrate folder for the default database
|
32
|
+
|
21
33
|
And I should see a migration file in the db/migrate folder in a multi database app
|
22
34
|
And I run `rails generate multi_migration CreateFoolsTable users` in a multi database app
|
23
35
|
Then I should see the db/users_migrate folder for the default database
|
@@ -1,10 +1,9 @@
|
|
1
|
+
|
1
2
|
class MultiMigrationGenerator < Rails::Generators::NamedBase
|
2
3
|
include Rails::Generators::Migration
|
3
|
-
|
4
|
-
argument :database_name, :type => :string, :required => true, :banner => 'DBNAME'
|
4
|
+
argument :database_name, :type => :string, :required => false, :banner => 'DBNAME'
|
5
5
|
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
6
6
|
|
7
|
-
hook_for :orm, :required => true
|
8
7
|
|
9
8
|
source_root File.expand_path('../templates', __FILE__)
|
10
9
|
|
@@ -13,7 +12,7 @@ class MultiMigrationGenerator < Rails::Generators::NamedBase
|
|
13
12
|
if ActiveRecord::Base.timestamped_migrations
|
14
13
|
[Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
|
15
14
|
else
|
16
|
-
|
15
|
+
SchemaMigration.normalize_migration_number(next_migration_number)
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
@@ -23,21 +22,28 @@ class MultiMigrationGenerator < Rails::Generators::NamedBase
|
|
23
22
|
end
|
24
23
|
|
25
24
|
def migration_directory
|
26
|
-
if database_name == "default"
|
25
|
+
if (database_name == "default") || database_is_nil?
|
27
26
|
"db/migrate/#{file_name}.rb"
|
28
27
|
else
|
29
28
|
"db/#{database_name.downcase}_migrate/#{file_name}.rb"
|
30
29
|
end
|
31
30
|
end
|
31
|
+
|
32
|
+
def database_is_nil?
|
33
|
+
db_name = database_name
|
34
|
+
return true if db_name.nil?
|
35
|
+
end
|
32
36
|
|
33
37
|
protected
|
34
|
-
attr_reader :migration_action
|
35
38
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
attr_reader :migration_action
|
40
|
+
|
41
|
+
def set_local_assigns!
|
42
|
+
if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
|
43
|
+
@migration_action = $1
|
44
|
+
@table_name = $2.pluralize
|
41
45
|
end
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
49
|
+
|
data/multi-db-dummy/Gemfile.lock
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi-database-9000
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Weston
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -281,7 +281,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
281
|
version: '0'
|
282
282
|
requirements: []
|
283
283
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.4.
|
284
|
+
rubygems_version: 2.4.5
|
285
285
|
signing_key:
|
286
286
|
specification_version: 4
|
287
287
|
summary: Enables Rails apps with multiple databases to handle migrations and rake
|