Skip to content

Commit b66f5b8

Browse files
authored
Add DB migration to fix now invalid User.names values that are already in DB
1 parent ce23dbd commit b66f5b8

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Copyright 2016 Eugene Frolov <eugene@frolov.net.ru>
2+
#
3+
# All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License. You may obtain
7+
# a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
# License for the specific language governing permissions and limitations
15+
# under the License.
16+
17+
from restalchemy.storage.sql import migrations
18+
19+
20+
class MigrationStep(migrations.AbstarctMigrationStep):
21+
22+
def __init__(self):
23+
self._depends = ["0023-nullable_fio-c9cb3a.py"]
24+
25+
@property
26+
def migration_id(self):
27+
return "6b042b1d-df57-4553-a031-8ae74ffab015"
28+
29+
@property
30+
def is_manual(self):
31+
return True
32+
33+
def upgrade(self, session):
34+
expression = """
35+
UPDATE iam_users
36+
SET
37+
name = REPLACE(name, '@', '.at.')
38+
WHERE name LIKE '%@%';
39+
"""
40+
session.execute(expression)
41+
42+
def downgrade(self, session):
43+
expression = """
44+
UPDATE iam_users
45+
SET
46+
name = REPLACE(name, '.at.', '@')
47+
WHERE name LIKE '%.at.%';
48+
"""
49+
session.execute(expression)
50+
51+
52+
migration_step = MigrationStep()

0 commit comments

Comments
 (0)