-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
259 additions
and
58 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
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
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
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,33 @@ | ||
from django.db import connection, transaction | ||
from file.models import File | ||
|
||
|
||
def migrate_files( | ||
target_project: int, | ||
dest_project: int, | ||
id_mapping: list[tuple[int, int]] | ||
): | ||
with transaction.atomic(): | ||
files = File.objects.filter(project_id=target_project) | ||
|
||
assert files.update(project_id=dest_project, rebound_project=target_project), "No File to update" | ||
|
||
update_attributes_query = """ | ||
update attribute_group_attribute | ||
set attribute_id = %s | ||
where attributegroup_id in %s and attribute_id = %s; | ||
""" | ||
|
||
ag_id_list = tuple([ | ||
str(uid) for uid | ||
in files.values_list("attributegroup__uid", flat=True).distinct() | ||
]) | ||
|
||
query_values = [ | ||
(dest_id, ag_id_list, target_id) | ||
for target_id, dest_id | ||
in id_mapping | ||
] | ||
|
||
with connection.cursor() as cursor: | ||
cursor.executemany(update_attributes_query, query_values) |
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
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
Oops, something went wrong.