sql: run role migrations in sql mode (#67190)
This commit is contained in:
parent
35e5dac0a7
commit
88506eb4a2
|
@ -2,6 +2,7 @@ import pickle
|
|||
|
||||
from quixote import get_publisher
|
||||
|
||||
from wcs import sql
|
||||
from wcs.roles import get_user_roles
|
||||
|
||||
from .utilities import clean_temporary_pub, create_temporary_pub
|
||||
|
@ -38,13 +39,13 @@ def test_migrate():
|
|||
get_publisher().role_class.wipe()
|
||||
role = get_publisher().role_class(name='Hello world')
|
||||
role.store()
|
||||
with open(role.get_object_filename(), 'rb') as fd:
|
||||
obj = pickle.load(fd)
|
||||
del obj.slug
|
||||
with open(role.get_object_filename(), 'wb') as fd:
|
||||
pickle.dump(obj, fd)
|
||||
with open(role.get_object_filename(), 'rb') as fd:
|
||||
assert pickle.load(fd).slug is None
|
||||
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
sql_statement = 'UPDATE roles SET slug = NULL'
|
||||
cur.execute(sql_statement)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
assert get_publisher().role_class.get(role.id).slug == 'hello-world'
|
||||
|
||||
|
||||
|
|
|
@ -3264,6 +3264,14 @@ class Role(SqlMixin, wcs.roles.Role):
|
|||
|
||||
_numerical_id = False
|
||||
|
||||
@classmethod
|
||||
def get(cls, id, ignore_errors=False, ignore_migration=False, column=None):
|
||||
o = super().get(id, ignore_errors=ignore_errors, ignore_migration=ignore_migration, column=column)
|
||||
if o and not ignore_migration:
|
||||
if o.migrate():
|
||||
o.store()
|
||||
return o
|
||||
|
||||
@guard_postgres
|
||||
def store(self):
|
||||
if self.slug is None:
|
||||
|
|
Loading…
Reference in New Issue