multitenancy_tools 0.1.10 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38a295e4d0fb3dc90035639d066137927c576551
4
- data.tar.gz: f0ee6b1bd47bf9d4f357b599fd88aab97c7a2bfe
3
+ metadata.gz: 492c6182c4299f4b2895b9b4709a481c202727a7
4
+ data.tar.gz: ffa962fe311628d2d51d8e84238d980ee0905b79
5
5
  SHA512:
6
- metadata.gz: 1c354ac59d1a9bdd44ebcd9832f69b16e794d086104b9d8fa1ba9361c86b82715f48220479ba5a31091c3f90bc7af3e84e7028f58a78cc3ef1c9747fb1930720
7
- data.tar.gz: acdf161ac4b73e1c57c9631c5d836d3fb892312a487d1ff9f9266d92fac985f37ca58b96e2d7a613e970954c60d48a8e0e500198627bf97c0b22f5d7f61aafd0
6
+ metadata.gz: 346b3a9769bc400f4dcc11704a0a1734bba480a165ce8bfd4e03148f9e25ce96d05ed2ad39a9d02b1b9824cb40c8b2786ccc64ba121a6a3ce3e72c91ec44962e
7
+ data.tar.gz: fd44ff73caf4949a6d91a659b08439a4b1f105920747b289ab6ae7fb8c68541acd3c511802c0419102bad5617a5e641cf94a6146ef5c70a9fbd4c1ead4ed782e
@@ -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
@@ -1,3 +1,3 @@
1
1
  module MultitenancyTools
2
- VERSION = '0.1.10'
2
+ VERSION = '0.1.11'
3
3
  end
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_dependency 'activerecord', '~> 4.2.0'
24
+ spec.add_dependency 'activesupport', '~> 4.2.0'
24
25
  spec.add_dependency 'pg'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.10'
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.10
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-08-18 00:00:00.000000000 Z
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