ec-pg 0.1.9 → 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 +4 -4
- data/lib/ec/pg/migration_mixin.rb +34 -0
- data/lib/ec/pg/version.rb +1 -1
- data/lib/ec/pg.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffe4813266a9c664a415549779456ef3da7f2ef8ba7be5fa27c7a9f355ec76af
|
|
4
|
+
data.tar.gz: 2d20b237a2e705ff121e29cfbfc6fc4d19afef4b89843c240d354c2fc1471f06
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/ec/pg/version.rb
CHANGED
data/lib/ec/pg.rb
CHANGED
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
|
+
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
|