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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e3148b716e1640ca06c7f78be79198b1ad804d36fb06f1bebe9ea6aaa06f63
|
4
|
+
data.tar.gz: ffa7fbe4ebab51049c781bb592799ff631df980d352b7af8d096749ebc76a58d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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();'
|