multitenancy_tools 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multitenancy_tools.rb +1 -0
- data/lib/multitenancy_tools/schema_migrator.rb +45 -0
- data/lib/multitenancy_tools/version.rb +1 -1
- data/multitenancy_tools.gemspec +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 492c6182c4299f4b2895b9b4709a481c202727a7
|
4
|
+
data.tar.gz: ffa962fe311628d2d51d8e84238d980ee0905b79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 346b3a9769bc400f4dcc11704a0a1734bba480a165ce8bfd4e03148f9e25ce96d05ed2ad39a9d02b1b9824cb40c8b2786ccc64ba121a6a3ce3e72c91ec44962e
|
7
|
+
data.tar.gz: fd44ff73caf4949a6d91a659b08439a4b1f105920747b289ab6ae7fb8c68541acd3c511802c0419102bad5617a5e641cf94a6146ef5c70a9fbd4c1ead4ed782e
|
data/lib/multitenancy_tools.rb
CHANGED
@@ -7,6 +7,7 @@ require 'multitenancy_tools/table_dumper'
|
|
7
7
|
require 'multitenancy_tools/schema_switcher'
|
8
8
|
require 'multitenancy_tools/schema_destroyer'
|
9
9
|
require 'multitenancy_tools/functions_dumper'
|
10
|
+
require 'multitenancy_tools/schema_migrator'
|
10
11
|
|
11
12
|
module MultitenancyTools
|
12
13
|
# Creates a new schema using the SQL file as template. This SQL file can be
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/core_ext/kernel/reporting'
|
2
|
+
|
3
|
+
module MultitenancyTools
|
4
|
+
# {SchemaMigrator} is a wrapper around ActiveRecord::Migrator that executes
|
5
|
+
# all migrations inside a PostgreSQL schema.
|
6
|
+
#
|
7
|
+
# Unfortunately this can only execute migrations using the global connection
|
8
|
+
# (the connection returned by ActiveRecord::Base.connection).
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# migrator = MultitenancyTools::SchemaMigrator.new('my_schema', 'path/to/migrations')
|
12
|
+
# migrator.migrate
|
13
|
+
class SchemaMigrator
|
14
|
+
# @param schema [String] schema name
|
15
|
+
# @param migrations_path [String] path to the migrations files
|
16
|
+
def initialize(schema, migrations_path)
|
17
|
+
@schema = schema
|
18
|
+
@migrations_path = migrations_path
|
19
|
+
end
|
20
|
+
|
21
|
+
# Executes all migrations.
|
22
|
+
def migrate
|
23
|
+
run do
|
24
|
+
ActiveRecord::Migrator.migrate(@migrations_path, nil)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Undo the latest migration.
|
29
|
+
def rollback
|
30
|
+
run do
|
31
|
+
ActiveRecord::Migrator.rollback(@migrations_path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def run(&block)
|
38
|
+
SchemaSwitcher.new(@schema, ActiveRecord::Base.connection).run do
|
39
|
+
silence_stream(STDOUT) do
|
40
|
+
yield
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/multitenancy_tools.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multitenancy_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lenon Marcel
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2015-
|
14
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: activerecord
|
@@ -27,6 +27,20 @@ dependencies:
|
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 4.2.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: activesupport
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 4.2.0
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 4.2.0
|
30
44
|
- !ruby/object:Gem::Dependency
|
31
45
|
name: pg
|
32
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,6 +151,7 @@ files:
|
|
137
151
|
- lib/multitenancy_tools/schema_creator.rb
|
138
152
|
- lib/multitenancy_tools/schema_destroyer.rb
|
139
153
|
- lib/multitenancy_tools/schema_dumper.rb
|
154
|
+
- lib/multitenancy_tools/schema_migrator.rb
|
140
155
|
- lib/multitenancy_tools/schema_switcher.rb
|
141
156
|
- lib/multitenancy_tools/table_dumper.rb
|
142
157
|
- lib/multitenancy_tools/version.rb
|