-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(environments): Add migration to backfill projects (#20887)
* chore(environments): Add migration to backfill projects * Fix `noop` * Add `project_id` to plugin server test setup * Fix `project_id` * Also add `posthog_project` to plugin server tests * Update `createTeam` * Fix func tests
- Loading branch information
Showing
5 changed files
with
74 additions
and
9 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,41 @@ | ||
# Generated by Django 4.1.13 on 2024-03-12 23:14 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("posthog", "0396_projects_and_environments"), | ||
] | ||
|
||
operations = [ | ||
migrations.SeparateDatabaseAndState( | ||
database_operations=[ | ||
migrations.RunSQL( | ||
sql=""" | ||
-- For each team without a parent project, create such a project | ||
INSERT INTO posthog_project (id, name, created_at, organization_id) | ||
SELECT id, name, created_at, organization_id | ||
FROM posthog_team | ||
WHERE project_id IS NULL; | ||
-- At this point, all teams have a parent project, so we can safely set project_id on every team | ||
UPDATE posthog_team | ||
SET project_id = id;""", | ||
reverse_sql=migrations.RunSQL.noop, | ||
) | ||
], | ||
state_operations=[ | ||
migrations.AlterField( | ||
model_name="team", | ||
name="project", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="teams", | ||
related_query_name="team", | ||
to="posthog.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