-
Notifications
You must be signed in to change notification settings - Fork 938
/
d18d443f89f0_ultranormalize_name_function.py
55 lines (48 loc) · 1.57 KB
/
d18d443f89f0_ultranormalize_name_function.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
ultranormalize_name function
Revision ID: d18d443f89f0
Revises: d582fb87b94c
Create Date: 2021-12-17 06:25:19.035417
"""
from alembic import op
revision = "d18d443f89f0"
down_revision = "d582fb87b94c"
def upgrade():
op.execute(
r"""
CREATE FUNCTION ultranormalize_name(text) RETURNS text AS $$
SELECT lower(
regexp_replace(
regexp_replace(
regexp_replace($1, '(\.|_|-)', '', 'ig'),
'(l|L|i|I)', '1', 'ig'
),
'(o|O)', '0', 'ig'
)
)
$$
LANGUAGE SQL
IMMUTABLE
RETURNS NULL ON NULL INPUT;
"""
)
op.execute(
""" CREATE INDEX project_name_ultranormalized
ON projects
(ultranormalize_name(name))
"""
)
def downgrade():
op.execute("DROP INDEX project_name_ultranormalized")
op.execute("DROP FUNCTION ultranormalize_name(text)")