-
Notifications
You must be signed in to change notification settings - Fork 522
feat(experimentation): one warehouse connection per environment #7582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("experimentation", "0002_add_config_and_created_status"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveConstraint( | ||
| model_name="warehouseconnection", | ||
| name="unique_active_warehouse_per_type_and_env", | ||
| ), | ||
| migrations.AddConstraint( | ||
| model_name="warehouseconnection", | ||
| constraint=models.UniqueConstraint( | ||
| condition=models.Q(("deleted_at__isnull", True)), | ||
| fields=("environment",), | ||
| name="unique_active_warehouse_per_env", | ||
| ), | ||
| ), | ||
| ] | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,13 +55,14 @@ def create( | |||||||||||||||||||||||||||||||||||||||
| WarehouseConnection.objects.all_with_deleted() | ||||||||||||||||||||||||||||||||||||||||
| .filter( | ||||||||||||||||||||||||||||||||||||||||
| environment=environment, | ||||||||||||||||||||||||||||||||||||||||
| warehouse_type=warehouse_type, | ||||||||||||||||||||||||||||||||||||||||
| deleted_at__isnull=False, | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| .order_by("-deleted_at") | ||||||||||||||||||||||||||||||||||||||||
| .first() | ||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||
| if existing: | ||||||||||||||||||||||||||||||||||||||||
| existing.deleted_at = None | ||||||||||||||||||||||||||||||||||||||||
| existing.warehouse_type = warehouse_type | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
57
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resurrecting a soft-deleted connection and changing its
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| existing.status = WarehouseConnectionStatus.CREATED | ||||||||||||||||||||||||||||||||||||||||
| existing.name = validated_data["name"] | ||||||||||||||||||||||||||||||||||||||||
| existing.config = validated_data.get("config") | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This migration will fail if any environment currently has multiple active warehouse connections of different types. Since the previous constraint (
unique_active_warehouse_per_type_and_env) allowed one connection per type, an environment could have both a Snowflake and a Flagsmith connection active. You should include a data migration to resolve these duplicates (e.g., by soft-deleting all but the most recent one) before applying this new constraint.