-
Notifications
You must be signed in to change notification settings - Fork 2
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
12 changed files
with
178 additions
and
35 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
89 changes: 89 additions & 0 deletions
89
bots/migrations/0043_botintegration_user_savedrun_user_and_more.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,89 @@ | ||
# Generated by Django 4.2.3 on 2023-09-19 21:52 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
from django.db.models import Subquery, OuterRef | ||
|
||
|
||
def forwards_func(apps, schema_editor): | ||
AppUser = apps.get_model("app_users", "AppUser") | ||
SavedRun = apps.get_model("bots", "SavedRun") | ||
BotIntegration = apps.get_model("bots", "BotIntegration") | ||
db_alias = schema_editor.connection.alias | ||
user_objects = AppUser.objects.using(db_alias) | ||
SavedRun.objects.using(db_alias).filter(uid__isnull=False).update( | ||
user=Subquery( | ||
user_objects.filter(uid=OuterRef("uid")).values("pk")[:1], | ||
), | ||
) | ||
BotIntegration.objects.using(db_alias).all().update( | ||
user=Subquery( | ||
user_objects.filter(uid=OuterRef("billing_account_uid")).values("pk")[:1], | ||
), | ||
) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("app_users", "0006_appuser_disable_safety_checker"), | ||
("bots", "0042_alter_message_platform_msg_id"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="botintegration", | ||
name="user", | ||
field=models.ForeignKey( | ||
default=None, | ||
help_text="The gooey account uid where the credits will be deducted from", | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="bot_integrations", | ||
to="app_users.appuser", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="savedrun", | ||
name="user", | ||
field=models.ForeignKey( | ||
blank=True, | ||
default=None, | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_NULL, | ||
related_name="saved_runs", | ||
to="app_users.appuser", | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="botintegration", | ||
name="billing_account_uid", | ||
field=models.TextField( | ||
db_index=True, help_text="DEPRECATED: use user field instead" | ||
), | ||
), | ||
migrations.AlterField( | ||
model_name="savedrun", | ||
name="uid", | ||
field=models.CharField( | ||
blank=True, | ||
default=None, | ||
help_text="DEPRECATED: use user filed instead", | ||
max_length=128, | ||
null=True, | ||
), | ||
), | ||
migrations.RunPython( | ||
forwards_func, | ||
migrations.RunPython.noop, | ||
), | ||
migrations.RemoveIndex( | ||
model_name="botintegration", | ||
name="bots_botint_billing_466a86_idx", | ||
), | ||
migrations.AddIndex( | ||
model_name="botintegration", | ||
index=models.Index( | ||
fields=["user", "platform"], name="bots_botint_user_id_2c82dd_idx" | ||
), | ||
), | ||
] |
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
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
Oops, something went wrong.