-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migration: add migration for user models
Since the `User` schema has been changed, add a migration for it. Signed-off-by: Jeny Sadadia <[email protected]>
- Loading branch information
Jeny Sadadia
committed
Nov 2, 2023
1 parent
3cc1fc0
commit a8133f7
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# SPDX-License-Identifier: LGPL-2.1-or-later | ||
# | ||
# Copyright (C) 2022 Collabora Limited | ||
# Author: Jeny Sadadia <[email protected]> | ||
|
||
""" | ||
Migration for User schema | ||
""" | ||
|
||
name = '20231102101356_user' | ||
dependencies = ['20221014061654_set_timeout'] | ||
|
||
|
||
def upgrade(db: "pymongo.database.Database"): | ||
users = db.user.find() | ||
for user in users: | ||
db.user.replace_one( | ||
{ | ||
"_id": user['_id'] | ||
}, | ||
{ | ||
"_id": user['_id'], | ||
"email": user['profile']['email'], | ||
"hashed_password": user['profile']['hashed_password'], | ||
"is_active": 1, | ||
"is_superuser": 0, | ||
"is_verified": 0, | ||
"username": user['profile']['username'], | ||
"groups": user['profile']['groups'] | ||
}, | ||
) | ||
|
||
|
||
def downgrade(db: "pymongo.database.Database"): | ||
pass |