-
Notifications
You must be signed in to change notification settings - Fork 4
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
9 changed files
with
149 additions
and
121 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
69 changes: 69 additions & 0 deletions
69
terraso_backend/apps/project_management/migrations/0026_alter_project_privacy.py
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,69 @@ | ||
# Copyright © 2024 Technology Matters | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see https://www.gnu.org/licenses/. | ||
|
||
# Generated by Django 5.0.2 on 2024-03-14 23:15 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
def migrate_data(apps, schema_editor): | ||
Project = apps.get_model("project_management", "Project") | ||
Project.objects.filter(privacy_old="private").update(privacy="PRIVATE") | ||
Project.objects.filter(privacy_old="public").update(privacy="PUBLIC") | ||
|
||
Membership = apps.get_model("collaboration", "Membership") | ||
project_memberships = Membership.objects.filter(membership_list__project__isnull=False) | ||
project_memberships.filter(user_role="manager").update(user_role="MANAGER") | ||
project_memberships.filter(user_role="contributor").update(user_role="CONTRIBUTOR") | ||
project_memberships.filter(user_role="viewer").update(user_role="VIEWER") | ||
|
||
|
||
def unmigrate_data(apps, schema_editor): | ||
Project = apps.get_model("project_management", "Project") | ||
Project.objects.filter(privacy="PRIVATE").update(privacy_old="private") | ||
Project.objects.filter(privacy="PUBLIC").update(privacy_old="public") | ||
|
||
Membership = apps.get_model("collaboration", "Membership") | ||
project_memberships = Membership.objects.filter(membership_list__project__isnull=False) | ||
project_memberships.filter(user_role="MANAGER").update(user_role="manager") | ||
project_memberships.filter(user_role="CONTRIBUTOR").update(user_role="contributor") | ||
project_memberships.filter(user_role="VIEWER").update(user_role="viewer") | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("project_management", "0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more"), | ||
("collaboration", "0006_membership_status_approved_lowercase"), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField(model_name="project", old_name="privacy", new_name="privacy_old"), | ||
migrations.AddField( | ||
model_name="project", | ||
name="privacy", | ||
field=models.CharField( | ||
choices=[("PRIVATE", "Private"), ("PUBLIC", "Public")], | ||
default="PRIVATE", | ||
max_length=32, | ||
), | ||
), | ||
migrations.RunPython(migrate_data, unmigrate_data), | ||
migrations.RemoveField(model_name="project", name="privacy_old"), | ||
migrations.RemoveField( | ||
model_name="project", | ||
name="measurement_units", | ||
), | ||
] |
Oops, something went wrong.