better_record 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdba9a47098a0a01e86fcaebd7c82c5d2c896dec9b8d7df67c3235f26c94b495
4
- data.tar.gz: a05cbc82c831fbf2d063355afe66c66bf4404432af3e78c89baf625f1eba530d
3
+ metadata.gz: b1e3148b716e1640ca06c7f78be79198b1ad804d36fb06f1bebe9ea6aaa06f63
4
+ data.tar.gz: ffa7fbe4ebab51049c781bb592799ff631df980d352b7af8d096749ebc76a58d
5
5
  SHA512:
6
- metadata.gz: 294de3be50905c60b2ccfa414a1a3d362d46b7ce9a1dd088581c7d4069eed8bfe85685aab234893bd793aea2dc0d1a9f4b437d2617b59398a12ccb54985598e0
7
- data.tar.gz: 4f7e75b61f6831e27fe088c04aea60918ffbf019dfa823bdadb0e33e4508c54239a4856ff18e9b5f7dcf11a351febbc5c3526482ab9a6c9b81fc30d28854e1df
6
+ metadata.gz: e29cb8cd89960abe633cdf6b7eea7808fc7743dcad51e41b30d619c3462aa15c692c3cc07e11820b52857c6d541bfce200dba0429ad77b0108c6dea524083c48
7
+ data.tar.gz: 7fe66330d09156c97e8f835a8128f89222bece19c0794b17f02af1b63bc58311649145c0096ef869a1311ac6ee6fa46190d54f08b5be00d6b9224fb6b98a27e9
@@ -82,9 +82,59 @@ class CreateBetterRecordDBFunctions < ActiveRecord::Migration[5.2]
82
82
  LANGUAGE plpgsql;
83
83
  SQL
84
84
 
85
+ execute <<-SQL
86
+ CREATE OR REPLACE FUNCTION unique_random_string(table_name text, column_name text, string_length integer)
87
+ RETURNS text AS
88
+ $BODY$
89
+ DECLARE
90
+ key TEXT;
91
+ qry TEXT;
92
+ found TEXT;
93
+ letter TEXT;
94
+ iterator INTEGER;
95
+ BEGIN
96
+
97
+ qry := 'SELECT ' || column_name || ' FROM ' || table_name || ' WHERE ' || column_name || '=';
98
+
99
+ LOOP
100
+
101
+ key := '';
102
+ iterator := 0;
103
+
104
+ WHILE iterator < string_length
105
+ LOOP
106
+
107
+ SELECT c INTO letter
108
+ FROM regexp_split_to_table(
109
+ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
110
+ ''
111
+ ) c
112
+ ORDER BY random()
113
+ LIMIT 1;
114
+
115
+ key := key || letter;
116
+
117
+ iterator := iterator + 1;
118
+ END LOOP;
119
+
120
+ EXECUTE qry || quote_literal(key) INTO found;
121
+
122
+ IF found IS NULL THEN
123
+ EXIT;
124
+ END IF;
125
+
126
+ END LOOP;
127
+
128
+ RETURN key;
129
+ END;
130
+ $BODY$
131
+ LANGUAGE plpgsql;
132
+ SQL
133
+
85
134
  end
86
135
 
87
136
  def down
137
+ execute 'DROP FUNCTION IF EXISTS unique_random_string();'
88
138
  execute 'DROP FUNCTION IF EXISTS valid_email_trigger();'
89
139
  execute 'DROP FUNCTION IF EXISTS validate_email();'
90
140
  execute 'DROP FUNCTION IF EXISTS temp_table_exists();'
@@ -1,3 +1,3 @@
1
1
  module BetterRecord
2
- VERSION = '0.7.1'
2
+ VERSION = '0.7.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sampson Crowley