multi_ar 5.1.3 → 6.0.0.pre.beta
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/multi_ar/interface.rb +13 -4
- data/lib/multi_ar/rake/migration_generator.rb +2 -1
- data/lib/multi_ar/rake/tasks.rb +2 -1
- data/lib/multi_ar/version.rb +1 -1
- data/lib/multi_ar.rb +55 -7
- data.tar.gz.sig +0 -0
- metadata +36 -31
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be873bd564b04b81d3a4245160c98007dec42edb692cabf64ce1a4ae3e2b5ef
|
4
|
+
data.tar.gz: c33cbbed7eea9697166655ba9952e3155048c156975c82a20413bd99bb86b366
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a1152839e3967942d039eac8f6bc91a9ac572fe804f9d0cf1bbbc9aa040428d858350c5ed49d2dbcc3c2e0876bbc7a2801f606fb15876d2332e380d728af6f
|
7
|
+
data.tar.gz: 9ece6a831414d6bfbbdaf168db31e219ef3f161b31ad36e046da51f2244e2c06269da387217cd4250d7b96c81fa79cb665150afeb95a5d70a3db43623d9bb607
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/lib/multi_ar/interface.rb
CHANGED
@@ -65,6 +65,7 @@ module MultiAR
|
|
65
65
|
p.banner @description if @description
|
66
66
|
p.opt "init", "Create stub environment with configuration and database.yaml. " +
|
67
67
|
"For current dir, use “.”.", type: :string
|
68
|
+
p.opt "gem", "Run migrations from an installed gem", type: :string
|
68
69
|
p.opt "databases", "List of databases to perform operations", type: :strings if(@options["databases"] != false && !@options["databases"].respond_to?(:each))
|
69
70
|
p.opt "db_config", "Path to database config file", type: :string, default: DEFAULT_DB_CONFIG if @options["db_config"] == true
|
70
71
|
p.opt "config", "Path to MultiAR framework config file", type: :string, default: "config/settings.yaml" if @options["config"] == true
|
@@ -137,6 +138,7 @@ module MultiAR
|
|
137
138
|
opts[:db_config] = @opts["db_config"] unless @opts["db_config"].nil?
|
138
139
|
#opts[:migration_dirs] = [ @opts["migration_dir"] ]
|
139
140
|
opts[:config] = @opts["config"] unless @opts["config"].nil?
|
141
|
+
opts[:migrations_from_gem] = @opts["gem"] unless @opts["gem"].nil?
|
140
142
|
opts[:databases] = parse_databases_input(@opts["databases"])
|
141
143
|
opts[:environment] = @opts["environment"]
|
142
144
|
opts[:verbose] = @opts["verbose"]
|
@@ -155,7 +157,7 @@ module MultiAR
|
|
155
157
|
elsif !@options["migration_dir"].nil?
|
156
158
|
out[database] = "#{@options["migration_dir"]}/#{database}"
|
157
159
|
else
|
158
|
-
out[database] =
|
160
|
+
out[database] = nil
|
159
161
|
end
|
160
162
|
end
|
161
163
|
|
@@ -180,6 +182,8 @@ module MultiAR
|
|
180
182
|
File.write database_config, bootstrap_db_config(opts) unless File.exist?(database_config)
|
181
183
|
end
|
182
184
|
|
185
|
+
bootstrap_db_dir opts
|
186
|
+
|
183
187
|
bootstrap_config opts
|
184
188
|
end
|
185
189
|
|
@@ -191,9 +195,6 @@ module MultiAR
|
|
191
195
|
str = ""
|
192
196
|
databases = parse_databases_input(opts["databases"])
|
193
197
|
databases.each do |db, migration_path|
|
194
|
-
# This is a bit misleading place to create the migration dir, but it needs to be done somewhere.
|
195
|
-
FileUtils.mkdir_p(migration_path)
|
196
|
-
|
197
198
|
# Create the config file
|
198
199
|
[ "development", "production", "test"].each do |env|
|
199
200
|
full_name = "#{db}_#{env}"
|
@@ -211,6 +212,14 @@ module MultiAR
|
|
211
212
|
str
|
212
213
|
end
|
213
214
|
|
215
|
+
def bootstrap_db_dir opts
|
216
|
+
databases = parse_databases_input(opts["databases"])
|
217
|
+
databases.each do |db, migration_path|
|
218
|
+
migration_path = "db/migrate/#{db}" if migration_path.nil?
|
219
|
+
FileUtils.mkdir_p(migration_path)
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
214
223
|
def bootstrap_gemfile
|
215
224
|
|
216
225
|
str = <<-EOS.gsub(/^ {6}/, "")
|
@@ -10,7 +10,8 @@ module ActiveRecordMigrations
|
|
10
10
|
source_root ::ActiveRecord::Generators::MigrationGenerator.source_root
|
11
11
|
|
12
12
|
def db_migrate_path
|
13
|
-
|
13
|
+
database_name = MultiAR::MultiAR::databases.first[0]
|
14
|
+
MultiAR::MultiAR::solve_migration_path database_name
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/multi_ar/rake/tasks.rb
CHANGED
@@ -102,7 +102,8 @@ module Rake
|
|
102
102
|
multiple_databases_task "migrate", "db" do |database_name|
|
103
103
|
establish_connection database_name
|
104
104
|
|
105
|
-
|
105
|
+
migration_path = MultiAR::MultiAR::solve_migration_path database_name
|
106
|
+
context = ActiveRecord::MigrationContext.new(migration_path, ::ActiveRecord::Base.connection.schema_migration)
|
106
107
|
context.migrate
|
107
108
|
|
108
109
|
#MultiAR::MultiAR.migration_dirs.each do |dir|
|
data/lib/multi_ar/version.rb
CHANGED
data/lib/multi_ar.rb
CHANGED
@@ -19,6 +19,8 @@ module MultiAR
|
|
19
19
|
# This will always be overridden, when MultiAR is initialized. Don’t try to do any funny logic with this.
|
20
20
|
@@__databases = {}
|
21
21
|
|
22
|
+
@default_migration_path = "db/migrate"
|
23
|
+
|
22
24
|
class << self
|
23
25
|
# Instance of MultiAR::MultiAR, automatically assigned by MultiAR::MultiAR#new.
|
24
26
|
# Used internally in the gem, to access configuration and other internal parts.
|
@@ -27,7 +29,7 @@ module MultiAR
|
|
27
29
|
|
28
30
|
# @param databases array of available databases
|
29
31
|
# @todo config file is overriding parameters passed here... I think it should be other way around, but need more custom logic for that :/
|
30
|
-
def initialize databases: nil, environment: "development", config: "config/settings.yaml", db_config: "config/database.yaml", verbose: false
|
32
|
+
def initialize databases: nil, environment: "development", config: "config/settings.yaml", db_config: "config/database.yaml", verbose: false, migrations_from_gem: nil
|
31
33
|
|
32
34
|
# first load config
|
33
35
|
if not config.nil? and File.exist? config
|
@@ -46,6 +48,9 @@ module MultiAR
|
|
46
48
|
raise "#{db_config} is not valid path to a file. Try specifying --db-config <path> or configuring it in the configuration file." if db_config.nil? or !File.exist?(db_config)
|
47
49
|
#raise "databases is not responding to :each. Try passing passing --databases <database> or configuring it in the configuration file." unless databases.respond_to? :each
|
48
50
|
|
51
|
+
# One can run migrations from a gem, instead of current project.
|
52
|
+
load_migration_gem migrations_from_gem, databases if not migrations_from_gem.nil?
|
53
|
+
|
49
54
|
parse_databases_input databases unless databases.nil?
|
50
55
|
|
51
56
|
#@databases = databases
|
@@ -115,11 +120,13 @@ module MultiAR
|
|
115
120
|
#
|
116
121
|
# @note often you want to add full path to this dir, `__dir__` is useful for this.
|
117
122
|
def self.add_database database_name, migration_path
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
+
unless migration_path.nil?
|
124
|
+
raise "Migration dir #{migration_path} does not exist." unless Dir.exist? migration_path
|
125
|
+
begin
|
126
|
+
ActiveRecord::Tasks::DatabaseTasks.migrations_paths << migration_path
|
127
|
+
rescue NameError
|
128
|
+
# multi_ar can be used without migration support, so adding a database to migration paths is only necessary when actually running migrations.
|
129
|
+
end
|
123
130
|
end
|
124
131
|
@@__databases[database_name] = migration_path
|
125
132
|
end
|
@@ -141,6 +148,17 @@ module MultiAR
|
|
141
148
|
@@__databases
|
142
149
|
end
|
143
150
|
|
151
|
+
# Returns calculated migration path or if path have not been given, fallback to default db/migrate/DB_NAME if it exists.
|
152
|
+
def self.solve_migration_path database_name
|
153
|
+
path = self.databases[database_name]
|
154
|
+
if path.nil?
|
155
|
+
path = "db/migrate/#{database_name}"
|
156
|
+
raise "Trying to use migrations for non-existing database. Please specify database if you have migrations in custom location. Given database: #{database_name}" unless File.exist? path
|
157
|
+
end
|
158
|
+
|
159
|
+
path
|
160
|
+
end
|
161
|
+
|
144
162
|
# TODO: remember to remove these if not needed...
|
145
163
|
# Helper to resolve a path to database
|
146
164
|
#def self.resolve_database_path
|
@@ -152,6 +170,36 @@ module MultiAR
|
|
152
170
|
|
153
171
|
private
|
154
172
|
|
173
|
+
def load_migration_gem migrations_from_gem, databases
|
174
|
+
# If the gem is not installed, we just want to fail.
|
175
|
+
gem migrations_from_gem
|
176
|
+
|
177
|
+
spec = Gem.loaded_specs[migrations_from_gem]
|
178
|
+
gem_dir = nil
|
179
|
+
if spec.respond_to? :full_gem_path
|
180
|
+
gem_dir = spec.full_gem_path
|
181
|
+
else
|
182
|
+
require_paths = spec["require_paths"]
|
183
|
+
gem_dir = require_paths[0]
|
184
|
+
end
|
185
|
+
|
186
|
+
# This file contains gem specific details which can be used to bootstrap MultiAR.
|
187
|
+
# There could be default values, but for security, as loading arbitrary gems accidentally could cause hard-to-recognize security bugs, since migrations are plain Ruby code.
|
188
|
+
# TODO: document contents of that file somewhere.
|
189
|
+
info_file = "#{gem_dir}/config/multi_ar_gem.yaml"
|
190
|
+
|
191
|
+
raise "File #{info_file} does not exist. Please check that your gem contains config/multi_ar_gem.yaml for automatic operation." unless File.exist? info_file
|
192
|
+
yaml = YAML.load_file info_file
|
193
|
+
|
194
|
+
migration_dir = yaml["migration_dir"]
|
195
|
+
|
196
|
+
# Put in gem’s migration path, so stuff should just magically work
|
197
|
+
|
198
|
+
databases.each do |database, migration_path|
|
199
|
+
databases[database] = "#{gem_dir}/#{migration_dir}"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
155
203
|
# Supports three different input formats:
|
156
204
|
#
|
157
205
|
# 1. Array with strings of database names
|
@@ -163,7 +211,7 @@ module MultiAR
|
|
163
211
|
if database.kind_of? Hash
|
164
212
|
::MultiAR::MultiAR::add_database database["database"], database["migration_path"]
|
165
213
|
else
|
166
|
-
::MultiAR::MultiAR::add_database database, "
|
214
|
+
::MultiAR::MultiAR::add_database database, "#{default_migration_path}/#{database}"
|
167
215
|
end
|
168
216
|
end
|
169
217
|
return
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multi_ar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0.pre.beta
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samu Voutilainen
|
@@ -10,26 +10,31 @@ bindir: bin
|
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
MIIEMDCCApigAwIBAgIBATANBgkqhkiG9w0BAQsFADAhMR8wHQYDVQQDDBZydWJ5
|
14
|
+
Z2Vtcy9EQz1zbWFyL0RDPWZpMB4XDTE5MDgyODEwNTk0NVoXDTIwMDgyNzEwNTk0
|
15
|
+
NVowITEfMB0GA1UEAwwWcnVieWdlbXMvREM9c21hci9EQz1maTCCAaIwDQYJKoZI
|
16
|
+
hvcNAQEBBQADggGPADCCAYoCggGBANbCyT2d9Nu4OEjuYtxRfNn9sqPZlVB/iwnd
|
17
|
+
aCh2XphW7WSWNCPNVf1/V+SgD+Mi46XXSIZor3r4ja3yLR/0CcO9kIhZx7OHZfwh
|
18
|
+
uEpuU4S976ZY9DzPYVrr+crj6LXX7GEuEr5cgt9dZkf7f96yoMoZ9Rw8O2HOWn1G
|
19
|
+
GTZCtOpEsQcISuzrWnXXMmb44swiiQnmgEz9e+nbvFJnl9q7JJeIFaHkGXpXNemR
|
20
|
+
luRAQewsH8K6AnWjlLtyikhk/1OnKPdjRL4STo8fBiVzIQxoFejBCSlIBsGXW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aZAxvWI=
|
31
36
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
37
|
+
date: 2019-08-28 00:00:00.000000000 Z
|
33
38
|
dependencies:
|
34
39
|
- !ruby/object:Gem::Dependency
|
35
40
|
name: optimist
|
@@ -51,28 +56,28 @@ dependencies:
|
|
51
56
|
requirements:
|
52
57
|
- - "~>"
|
53
58
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
59
|
+
version: '6.0'
|
55
60
|
type: :runtime
|
56
61
|
prerelease: false
|
57
62
|
version_requirements: !ruby/object:Gem::Requirement
|
58
63
|
requirements:
|
59
64
|
- - "~>"
|
60
65
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
66
|
+
version: '6.0'
|
62
67
|
- !ruby/object:Gem::Dependency
|
63
68
|
name: rake
|
64
69
|
requirement: !ruby/object:Gem::Requirement
|
65
70
|
requirements:
|
66
71
|
- - "~>"
|
67
72
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
73
|
+
version: '12.3'
|
69
74
|
type: :runtime
|
70
75
|
prerelease: false
|
71
76
|
version_requirements: !ruby/object:Gem::Requirement
|
72
77
|
requirements:
|
73
78
|
- - "~>"
|
74
79
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
80
|
+
version: '12.3'
|
76
81
|
- !ruby/object:Gem::Dependency
|
77
82
|
name: safe_attributes
|
78
83
|
requirement: !ruby/object:Gem::Requirement
|
@@ -107,28 +112,28 @@ dependencies:
|
|
107
112
|
requirements:
|
108
113
|
- - "~>"
|
109
114
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
115
|
+
version: '3.0'
|
111
116
|
type: :development
|
112
117
|
prerelease: false
|
113
118
|
version_requirements: !ruby/object:Gem::Requirement
|
114
119
|
requirements:
|
115
120
|
- - "~>"
|
116
121
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
122
|
+
version: '3.0'
|
118
123
|
- !ruby/object:Gem::Dependency
|
119
124
|
name: cucumber
|
120
125
|
requirement: !ruby/object:Gem::Requirement
|
121
126
|
requirements:
|
122
127
|
- - "~>"
|
123
128
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
129
|
+
version: '3.1'
|
125
130
|
type: :development
|
126
131
|
prerelease: false
|
127
132
|
version_requirements: !ruby/object:Gem::Requirement
|
128
133
|
requirements:
|
129
134
|
- - "~>"
|
130
135
|
- !ruby/object:Gem::Version
|
131
|
-
version: '
|
136
|
+
version: '3.1'
|
132
137
|
- !ruby/object:Gem::Dependency
|
133
138
|
name: sqlite3
|
134
139
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,12 +195,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
190
195
|
version: '0'
|
191
196
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
197
|
requirements:
|
193
|
-
- - "
|
198
|
+
- - ">"
|
194
199
|
- !ruby/object:Gem::Version
|
195
|
-
version:
|
200
|
+
version: 1.3.1
|
196
201
|
requirements: []
|
197
202
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.7.
|
203
|
+
rubygems_version: 2.7.6.2
|
199
204
|
signing_key:
|
200
205
|
specification_version: 4
|
201
206
|
summary: Multi database feature set for ActiveRecord
|
metadata.gz.sig
CHANGED
Binary file
|