123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- # Generated by Django 5.0.7 on 2024-07-24 15:06
- from django.db import migrations, models
- # Disallow teams to be assigned to projects with a differing organization
- TEAM_PROJECT_TRIGGER = """
- CREATE OR REPLACE FUNCTION check_teamproject_organization() RETURNS TRIGGER AS $$
- BEGIN
- IF NEW.team_id IS NOT NULL AND NEW.project_id IS NOT NULL THEN
- PERFORM 1
- FROM projects_project p
- JOIN teams_team t ON t.organization_id = p.organization_id
- WHERE p.id = NEW.project_id AND t.id = NEW.team_id;
- IF NOT FOUND THEN
- RAISE EXCEPTION 'Team and Project must belong to the same organization';
- END IF;
- END IF;
- RETURN NEW;
- END;
- $$ LANGUAGE plpgsql;
- DROP TRIGGER IF EXISTS check_teamproject_organization_trigger ON teams_team_projects;
- CREATE TRIGGER check_teamproject_organization_trigger
- BEFORE INSERT OR UPDATE ON teams_team_projects
- FOR EACH ROW EXECUTE FUNCTION check_teamproject_organization();
- """
- class Migration(migrations.Migration):
- dependencies = [
- ("organizations_ext", "0004_organizationsubscription_alter_organization_slug"),
- ("projects", "0015_rename_label_projectkey_name_projectkey_is_active"),
- ("teams", "0001_squashed_0004_alter_team_id_alter_team_members"),
- ]
- operations = [
- migrations.AlterField(
- model_name="team",
- name="members",
- field=models.ManyToManyField(
- blank=True,
- related_name="teams",
- to="organizations_ext.organizationuser",
- ),
- ),
- migrations.AlterField(
- model_name="team",
- name="projects",
- field=models.ManyToManyField(related_name="teams", to="projects.project"),
- ),
- migrations.RunSQL(TEAM_PROJECT_TRIGGER, ""),
- ]
|