izolenta 0.0.3 → 0.0.4
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/CHANGELOG.md +5 -0
- data/README.md +9 -0
- data/lib/izolenta/active_record_migration.rb +7 -2
- data/lib/izolenta/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 377c2667d8659d69896c5e397347c69653641261159f04c404b0ec6e4007cefa
|
4
|
+
data.tar.gz: 3d552cc871bb52efd2e9c4e546145446818ac667f92033b21d2f7cdb7eaeafc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '094c5f7d6157445976aa017ee2ab757466ec21930a5f229da0a51d17928ffddd33e76862acacf340453885aac08ee0b3c5c67d3d6de5f8ea6a4bf96564bb3851'
|
7
|
+
data.tar.gz: 2d98b109bbb4809831aaa08c6504f7b6648f9ce9d4b53eb9211241417e60501ba3b5dea8ff3a5159d0542bd023b40f143364fb84a46f641570912cb9d56d521b
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
#0.0.4
|
2
|
+
- removed 'OR REPLACE' in trigger definition, lowering Postgres version constraint
|
3
|
+
- trigger_condition added ( could replace partial uniq index )
|
4
|
+
|
1
5
|
#0.0.3
|
2
6
|
- wrapper_function options added, you can define function to convert to uniquely sortable types, for instance array to string
|
7
|
+
- moved all helper functions to internal module, just to keep things clear on the migrations
|
3
8
|
|
4
9
|
#0.0.2
|
5
10
|
- delegate_uniqueness helper is available as a migration method
|
data/README.md
CHANGED
@@ -46,6 +46,15 @@ class WithWrapperFunctionMigration < ActiveRecord::Migration[5.0]
|
|
46
46
|
delegate_uniqueness( :your_table_name, :column_name, wrapper_function: 'type_conversion_function' )
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
|
51
|
+
class WithWrapperFunctionMigration < ActiveRecord::Migration[5.0]
|
52
|
+
# apply trigger condition for partial uniqueness
|
53
|
+
def change
|
54
|
+
delegate_uniqueness( :your_table_name, :column_name, trigger_condition: 'NEW.type IS NOT NULL' )
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
49
58
|
```
|
50
59
|
|
51
60
|
## Development
|
@@ -29,6 +29,9 @@ module Izolenta::ActiveRecordMigration
|
|
29
29
|
trg_name = "#{table}_#{column_name}_trg"
|
30
30
|
insert_value = options[:wrapper_function] ? "#{options[:wrapper_function]}(NEW.#{column_name})"
|
31
31
|
: "NEW.#{column_name}"
|
32
|
+
|
33
|
+
trigger_condition = "WHEN( #{options[:trigger_condition]} )" if options[:trigger_condition]
|
34
|
+
|
32
35
|
ActiveRecord::Base.connection.execute <<~SYNC_TRIGGER
|
33
36
|
CREATE OR REPLACE FUNCTION #{trg_name}() RETURNS trigger AS $$
|
34
37
|
BEGIN
|
@@ -36,7 +39,9 @@ module Izolenta::ActiveRecordMigration
|
|
36
39
|
RETURN NEW;
|
37
40
|
END $$ LANGUAGE plpgSQL;
|
38
41
|
|
39
|
-
CREATE
|
42
|
+
CREATE TRIGGER #{trg_name} BEFORE INSERT ON #{table}
|
43
|
+
FOR EACH ROW
|
44
|
+
#{trigger_condition}
|
40
45
|
EXECUTE FUNCTION #{trg_name}();
|
41
46
|
SYNC_TRIGGER
|
42
47
|
end
|
@@ -49,7 +54,7 @@ module Izolenta::ActiveRecordMigration
|
|
49
54
|
SYNC_TRIGGER
|
50
55
|
end
|
51
56
|
|
52
|
-
def get_new_column_type(origin_table, column, wrapper_function: nil)
|
57
|
+
def get_new_column_type(origin_table, column, wrapper_function: nil, **)
|
53
58
|
wrapper_function ? get_function_type(wrapper_function) : get_column_type(origin_table, column)
|
54
59
|
end
|
55
60
|
|
data/lib/izolenta/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: izolenta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pg
|