-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #807 from cortex-lab/removeProjectField
Remove project field
- Loading branch information
Showing
6 changed files
with
73 additions
and
21 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,39 @@ | ||
# Generated by Django 4.2.10 on 2024-03-14 14:28 | ||
import logging | ||
|
||
from django.db import migrations | ||
from django.db.models import F, Q | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def project2projects(apps, schema_editor): | ||
""" | ||
Find sessions where the project field (singular) value is not in the projects (plural) many-to-many | ||
field and updates them. | ||
Tested on local instance. | ||
""" | ||
Session = apps.get_model('actions', 'Session') | ||
sessions = Session.objects.exclude(Q(project__isnull=True) | Q(projects=F('project'))) | ||
|
||
# Check query worked | ||
# from one.util import ensure_list | ||
# for session in sessions.values('pk', 'project', 'projects'): | ||
# assert session['project'] not in ensure_list(session['projects']) | ||
|
||
for session in sessions: | ||
session.projects.add(session.project) | ||
# session.project = None | ||
# session.save() # No need to save | ||
|
||
assert Session.objects.exclude(Q(project__isnull=True) | Q(projects=F('project'))).count() == 0 | ||
logger.info(f'project -> projects: {sessions.count():,g} sessions updated') | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('actions', '0021_alter_session_extended_qc'), | ||
] | ||
|
||
operations = [migrations.RunPython(project2projects)] |
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,17 @@ | ||
# Generated by Django 4.2.10 on 2024-03-14 14:54 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('actions', '0022_project_to_projects'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='session', | ||
name='project', | ||
), | ||
] |
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