ec-pg 0.1.6 → 0.1.8

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: 96db794a56eb50815839a716d668cb9cb1309ab19e9a7dca540f72d67c6aa0b3
4
- data.tar.gz: 1a5ab8f3fc64bac9aaa3f965bb1698015e2d639af3819077dc051f7ae1bd016c
3
+ metadata.gz: 927ed76ae446cafa9cfa09623eb2ed3b05adf7973023c21de25353a95e7f59b2
4
+ data.tar.gz: 59865a939e8b813ec9872d4c27e9e5b7313dae76edf001cc175d79f41f76cb66
5
5
  SHA512:
6
- metadata.gz: 49b2648cdd99f5849d2aff3cfc55c49711aceef2e6a5d86ea7b66a19c3330daa2a2f3e382927aadd45b9a18d35984b064ed355e761a244b91ebfdaf227d87d06
7
- data.tar.gz: 73222c5fb6ef8dce5392fb4bf63a8a9b08fb93fd1d10d85df0648e06e4f18346e949a548ea90ca038112840771f0d403241f5ded7f64dbd9858840d6e6d25029
6
+ metadata.gz: 2e54504bc522de9c78e56344bae59e0b4661cc4fdce52ebc393ea210ab5c09d1fe1d49e8d7fc49b610f0c3ac729747ec82d028703d41ec9b7fb0650fee0337e9
7
+ data.tar.gz: 067f8f312bc09007fef2544b45a94f91f7c7e5196dc74101c736bef801875b3795b57f04ec156db2b647bb181acf159e7e6e25a77915d7a01e49786eb84b7978
@@ -81,9 +81,12 @@ module Ec
81
81
 
82
82
  # Builds the search_path string and executes SET search_path on the connection.
83
83
  def apply_schema(schema_name)
84
- registered_connections.each do |connection|
84
+ registered_models.each do |model|
85
+ connection = model.connection
85
86
  shared = Ec::Pg.configuration.shared_schemas
86
87
  path = ([schema_name] + shared).uniq.join(", ")
88
+
89
+ Ec::Pg.dprint("%s: Switching to schema: %s" % [model, path], color: :green)
87
90
  connection.schema_search_path = path
88
91
  end
89
92
  end
@@ -94,8 +97,10 @@ module Ec
94
97
  shared = Ec::Pg.configuration.shared_schemas
95
98
  path = ([default] + shared).uniq.join(", ")
96
99
 
97
- registered_connections.each do |connection|
100
+ registered_models.each do |model|
101
+ connection = model.connection
98
102
  if connection && connection.pool.present?
103
+ Ec::Pg.dprint("%s: Restoring schema to: %s" % [model, path], color: :red)
99
104
  connection.schema_search_path = path
100
105
  end
101
106
  end
@@ -103,10 +108,8 @@ module Ec
103
108
  # Swallow errors during cleanup (connection may have been returned to pool)
104
109
  end
105
110
 
106
- def registered_connections
107
- Ec::Pg::SchemaMixin
108
- .registered_models
109
- .map(&:connection)
111
+ def registered_models
112
+ Ec::Pg::SchemaMixin.registered_models
110
113
  end
111
114
 
112
115
  # Guards against SQL injection via schema names.
@@ -120,7 +123,7 @@ module Ec
120
123
  "Only alphanumeric characters and underscores are allowed."
121
124
  end
122
125
 
123
- module_function :apply_schema, :restore_schema, :validate_schema_name!, :registered_connections
126
+ module_function :apply_schema, :restore_schema, :validate_schema_name!, :registered_models
124
127
  end
125
128
  end
126
129
  end
@@ -20,19 +20,18 @@ module Ec
20
20
 
21
21
  # Layer composition: innermost layer first so that the outermost wrapper
22
22
  # controls the connection that the inner layers receive.
23
-
24
23
  run = block
25
24
 
26
25
  # 1. Schema (innermost)
27
26
  if schema
28
- inner_run = run
29
- run = -> {SchemaManager.with_schema(schema, &inner_run)}
27
+ schema_run = run
28
+ run = -> {SchemaManager.with_schema(schema, &schema_run)}
30
29
  end
31
30
 
32
31
  # 2. Shard (outermost — switches the connection first)
33
32
  if shard
34
- inner_run = run
35
- run = -> {ShardManager.with_shard(shard, &inner_run)}
33
+ shard_run = run
34
+ run = -> {ShardManager.with_shard(shard, &shard_run)}
36
35
  end
37
36
 
38
37
  if run.present?
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.6"
5
+ VERSION = "0.1.8"
6
6
  end
7
7
  end
data/lib/ec/pg.rb CHANGED
@@ -36,9 +36,9 @@ module Ec
36
36
 
37
37
  module_function
38
38
 
39
- def dprint(*args)
39
+ def dprint(message, color: :white)
40
40
  if ENV['ECPG_DEBUG']
41
- puts args
41
+ puts message.colorize(color)
42
42
  end
43
43
  end
44
44
 
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.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmhawash