ec-pg 0.1.8 → 0.1.10

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: 927ed76ae446cafa9cfa09623eb2ed3b05adf7973023c21de25353a95e7f59b2
4
- data.tar.gz: 59865a939e8b813ec9872d4c27e9e5b7313dae76edf001cc175d79f41f76cb66
3
+ metadata.gz: ffe4813266a9c664a415549779456ef3da7f2ef8ba7be5fa27c7a9f355ec76af
4
+ data.tar.gz: 2d20b237a2e705ff121e29cfbfc6fc4d19afef4b89843c240d354c2fc1471f06
5
5
  SHA512:
6
- metadata.gz: 2e54504bc522de9c78e56344bae59e0b4661cc4fdce52ebc393ea210ab5c09d1fe1d49e8d7fc49b610f0c3ac729747ec82d028703d41ec9b7fb0650fee0337e9
7
- data.tar.gz: 067f8f312bc09007fef2544b45a94f91f7c7e5196dc74101c736bef801875b3795b57f04ec156db2b647bb181acf159e7e6e25a77915d7a01e49786eb84b7978
6
+ metadata.gz: 62504aab93841d6051442cb3836afbf60edda564753e35770f72179239e85a44f8333f09a04c1a3990eb45d76e9c1d1c0b8a703d139f515c89ca35adbf195b37
7
+ data.tar.gz: 27deef7ab9f3213accfd76fbdedbe84baa9befb96a56b18b9f3700a509d2fb439bdca5c54e569e957614b3c4ad7c697c37dde1f9a79ccd6daedd259edb5f9220
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ec
4
+ module Pg
5
+ module MigrationMixin
6
+ def create_type(name, allow_blank: true)
7
+ values = allow_blank ? ['', 'null'] : []
8
+ values += I18n.t('database_types.%s' % name).absolute_deepest_keys.map(&:to_s)
9
+ quoted_values = values.map{|x| quote(x)}.join(',')
10
+ execute <<-SQL
11
+ CREATE TYPE #{Ec::Pg::SchemaManager.current_schema}.#{name} as ENUM (#{quoted_values});
12
+ SQL
13
+ end
14
+
15
+ def drop_type(name)
16
+ execute <<-SQL
17
+ DROP TYPE IF EXISTS #{Ec::Pg::SchemaManager.current_schema}.#{name};
18
+ SQL
19
+
20
+ end
21
+
22
+ def add_values_to_type(name, values, instruction = '')
23
+ execute('commit;') # The Alter Type query cannont happen inside a SQL transaction, so quit it.
24
+ values.each do |value|
25
+ execute "ALTER TYPE #{Ec::Pg::SchemaManager.current_schema}.#{name} ADD VALUE IF NOT EXISTS #{quote(value)} #{instruction}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ if Object.const_defined?("ActiveRecord::Migration")
33
+ ActiveRecord::Migration.send(:include, Ec::Pg::MigrationMixin)
34
+ end
@@ -16,7 +16,9 @@ module Ec
16
16
  Ec::Pg.switch(shard: shard) do
17
17
  schemas.each do |schema_name|
18
18
  Ec::Pg.dprint("migrating model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
19
- migrate_schema(model.connection, schema_name)
19
+ Context.with(schema: schema_name) do
20
+ migrate_schema(model.connection, schema_name)
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -31,7 +33,9 @@ module Ec
31
33
  Ec::Pg.switch(shard: shard) do
32
34
  schemas.each do |schema_name|
33
35
  Ec::Pg.dprint("rolling back model: #{model}, shard: #{shard}, schema: #{schema_name}".red)
34
- rollback_schema(model.connection, schema_name, steps)
36
+ Context.with(schema: schema_name) do
37
+ rollback_schema(model.connection, schema_name, steps)
38
+ end
35
39
  end
36
40
  end
37
41
  end
data/lib/ec/pg/version.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Ec
4
4
  module Pg
5
- VERSION = "0.1.8"
5
+ MINOR = 10
6
+ VERSION = "0.1.#{MINOR}"
6
7
  end
7
8
  end
data/lib/ec/pg.rb CHANGED
@@ -7,6 +7,7 @@ require_relative "pg/version"
7
7
  require_relative "pg/context"
8
8
  require_relative "pg/tenant_context"
9
9
  require_relative "pg/configuration"
10
+ require_relative "pg/migration_mixin"
10
11
 
11
12
  if ENV['RAILS_ENV'] == 'test'
12
13
  require 'debug'
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.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - gmhawash
@@ -153,6 +153,7 @@ files:
153
153
  - lib/ec/pg/configuration.rb
154
154
  - lib/ec/pg/context.rb
155
155
  - lib/ec/pg/middleware/context_switcher.rb
156
+ - lib/ec/pg/migration_mixin.rb
156
157
  - lib/ec/pg/migrator.rb
157
158
  - lib/ec/pg/mixin.rb
158
159
  - lib/ec/pg/railtie.rb
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  - !ruby/object:Gem::Version
193
194
  version: '0'
194
195
  requirements: []
195
- rubygems_version: 4.0.3
196
+ rubygems_version: 4.0.10
196
197
  specification_version: 4
197
198
  summary: Multitenant implemntations using shards, schemas and RLS
198
199
  test_files: []