-
Notifications
You must be signed in to change notification settings - Fork 12
v2.1.9 #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
v2.1.9 #291
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
22156bf
add script to archive old firebase projects
Hagellach37 ffd0dab
run black
Hagellach37 60f90b1
#281 #280 and fix exception for Firebase transfer function: use Trans…
Hagellach37 9ecec61
Merge pull request #281 from mapswipe/delete_old_projects
Hagellach37 b138da2
Revert "add script to archive old firebase projects"
Hagellach37 a5dbdbd
Merge pull request #286 from mapswipe/revert-281-delete_old_projects
Hagellach37 8a9e876
account for incomplete old projects #280
Hagellach37 5cae854
update data for archived projects correctly
Hagellach37 4c28f74
Merge pull request #288 from mapswipe/update-db-rule
Hagellach37 6cd5bcf
send success message from within try block #289
Hagellach37 2d6408b
Merge pull request #290 from mapswipe/fix_success_message
Hagellach37 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,91 @@ | ||
from mapswipe_workers import auth | ||
from mapswipe_workers.definitions import logger | ||
|
||
|
||
def get_old_projects(): | ||
""" | ||
Get all projects from Firebase which have been created | ||
before we switched to v2. | ||
""" | ||
fb_db = auth.firebaseDB() | ||
ref = fb_db.reference("projects") | ||
projects = ref.get() | ||
logger.info("got old projects from firebase") | ||
return projects | ||
|
||
|
||
def move_project_data_to_v2(project_id): | ||
""" | ||
Copy project information from old path to v2/projects in Firebase. | ||
Add status=archived attribute. | ||
Use Firebase transaction function for this. | ||
""" | ||
|
||
# Firebase transaction function | ||
def transfer(current_data): | ||
# we need to add these attributes | ||
# since they are expected for version 2 | ||
current_data["status"] = "archived" | ||
current_data["projectType"] = 1 | ||
current_data["projectId"] = str(project_id) | ||
current_data["progress"] = current_data.get("progress", 0) | ||
current_data["name"] = current_data.get("name", "unknown") | ||
fb_db.reference("v2/projects/{0}".format(project_id)).set(current_data) | ||
return dict() | ||
|
||
fb_db = auth.firebaseDB() | ||
projects_ref = fb_db.reference(f"projects/{project_id}") | ||
try: | ||
projects_ref.transaction(transfer) | ||
logger.info(f"{project_id}: Transfered project to v2 and delete in old path") | ||
return True | ||
except fb_db.TransactionAbortedError: | ||
logger.exception( | ||
f"{project_id}: Firebase transaction" | ||
f"for transferring project failed to commit" | ||
) | ||
return False | ||
|
||
|
||
def delete_old_groups(project_id): | ||
""" | ||
Delete old groups for a project | ||
""" | ||
fb_db = auth.firebaseDB() | ||
fb_db.reference("groups/{0}".format(project_id)).set({}) | ||
logger.info(f"deleted groups for: {project_id}") | ||
|
||
|
||
def delete_other_old_data(): | ||
""" | ||
Delete old imports, results, announcements in Firebase | ||
""" | ||
fb_db = auth.firebaseDB() | ||
fb_db.reference("imports").set({}) | ||
fb_db.reference("results").set({}) | ||
fb_db.reference("announcements").set({}) | ||
logger.info(f"deleted old results, imports, announcements") | ||
|
||
|
||
def archive_old_projects(): | ||
""" | ||
Run workflow to archive old projects. | ||
First get all old projects. | ||
Move project data to v2/projects in Firebase and | ||
set status=archived. | ||
Then delete all groups for a project. | ||
Finally, delete old results, imports and announcements. | ||
We don't touch the old user data in this workflow. | ||
""" | ||
|
||
projects = get_old_projects() | ||
for project_id in projects.keys(): | ||
if move_project_data_to_v2(project_id): | ||
delete_old_groups(project_id) | ||
else: | ||
logger.info(f"didn't delete project and groups for project: {project_id}") | ||
|
||
delete_other_old_data() | ||
|
||
|
||
archive_old_projects() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe
Retrieved {n_projects} MapSwipe v1 projects from firebase
?