ec-pg 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: fe77cf4fcd3e6dd213ece5869aa34f8d25114e448b42f428173e2fec8f3160ce
4
- data.tar.gz: f84123214c7dcf8d6a8abc0c5e676accf604649cb36d2b214b245b978449c2e4
3
+ metadata.gz: 63b59448c98ca14882ddcd20aab8efd9e35c3d970891ca2f97722a539ec31bd1
4
+ data.tar.gz: 592bba1d9afb65ca9ad8b49baa45b217c0f6872e5558abb90a0044e0e8a7b6ea
5
5
  SHA512:
6
- metadata.gz: b9361a94d4f3719a24a6dfda8240dc1c25bb2ce3c4780a4ff1bfa6cc697fba092028925a2803fa8c9818e00e8c32d705174bf459e8e05890bc6e806134c58f2d
7
- data.tar.gz: 2b9f3c7caffd8012a41fe60be30ac227c4b98b8e4abcf2c29cfeba016e3f8f629eb7023f63f672c8a6c625689663f86bef9e310046495d7895182c4ce9f539c0
6
+ metadata.gz: 38921ca6212c3e0a5468db148a1b663adccc23c463c8fc12c2b00a497b6696a83109e8b76c2597c947e06afbf1878607beb235532ab2b64157f7497c2d913391
7
+ data.tar.gz: aa7e5b7f89c86a26c0f1171f227fb4a5664a2fc6d381f263c69368a11347acb8c8571da3b1f22baff9322468d34c5a1e0c9c2e58f15fa0061d0bdc3a5c99472a
@@ -14,9 +14,9 @@ module Ec
14
14
  Ec::Pg::SchemaMixin.registered_models.each do |model|
15
15
  model.schemas.each do |shard, schemas|
16
16
  Ec::Pg.switch(shard: shard) do
17
- schemas.each do |schema|
18
- Ec::Pg.dprint("migrating model: #{model}, shard: #{shard}, schema: #{schema}".red)
19
- migrate_schema(model.connection.pool, schema)
17
+ schemas.each do |schema_name|
18
+ Ec::Pg.dprint("migrating model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
19
+ migrate_schema(model.connection, schema_name)
20
20
  end
21
21
  end
22
22
  end
@@ -29,9 +29,9 @@ module Ec
29
29
  Ec::Pg::SchemaMixin.registered_models.each do |model|
30
30
  model.schemas.each do |shard, schemas|
31
31
  Ec::Pg.switch(shard: shard) do
32
- schemas.each do |schema|
33
- Ec::Pg.dprint("rolling back model: #{model}, shard: #{shard}, schema: #{schema}".red)
34
- rollback_schema(model.connection.pool, schema, steps)
32
+ schemas.each do |schema_name|
33
+ Ec::Pg.dprint("rolling back model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
34
+ rollback_schema(model.connection, schema_name, steps)
35
35
  end
36
36
  end
37
37
  end
@@ -41,16 +41,22 @@ module Ec
41
41
 
42
42
  private
43
43
 
44
- def rollback_schema(pool, schema_name, steps)
45
- ActiveRecord::Base.establish_connection(pool.db_config)
46
- pool.schema_search_path = schema_name
47
- pool.migration_context.rollback(steps)
44
+ def rollback_schema(connection, schema_name, steps)
45
+ with_pool(connection, schema_name) do |pool|
46
+ pool.migration_context.rollback(steps)
47
+ end
48
48
  end
49
49
 
50
50
  def migrate_schema(pool, schema_name)
51
- ActiveRecord::Base.establish_connection(pool.db_config)
52
- pool.schema_search_path = schema_name
53
- pool.migration_context.migrate
51
+ with_pool(connection, schema_name) do |pool|
52
+ pool.migration_context.migrate
53
+ end
54
+ end
55
+
56
+ def with_pool(connection, schema_name)
57
+ ActiveRecord::Base.establish_connection(connection.pool.db_config)
58
+ connection.schema_search_path = schema_name
59
+ yield(connection.pool)
54
60
  end
55
61
  end
56
62
  end
data/lib/ec/pg/version.rb CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ec
4
4
  module Pg
5
- VERSION = "0.1.4"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec-pg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmhawash