-
Notifications
You must be signed in to change notification settings - Fork 26
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
delete broadcasts PR#1 #4056
delete broadcasts PR#1 #4056
Conversation
1. add is_active column with null=True 2. ensure is being set to True for new scheduled broadcasts (adding default=True to model will achive this)
Codecov Report
@@ Coverage Diff @@
## main #4056 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 440 441 +1
Lines 26856 26861 +5
=========================================
+ Hits 26856 26861 +5
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
migrations.AddField( | ||
model_name="broadcast", | ||
name="is_active", | ||
field=models.BooleanField(default=True, null=True), |
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.
Can't add the default in this step otherwise django will try to update every existing row with is_active=True
. If you run ./manage sqlmigrate msgs 0194
it'll show you the SQL that would be run for this migration and you'll see an UPDATE
like that. One of our databases has 7 million rows in this table which would require a longer lock than we can do. So what we do is.. a
- Add it without the default..
is_active = models.BooleanField(null=True)
- Run
makemigrations
.. - Add the default
is_active = models.BooleanField(null=True, default=True)
- Run
makemigrations
.. - (Optional for tidyness) manually move the operation from the second migration file into the first migration file so we have a single migration with 2 operations - the
AddField
and theAlterField
.
What that will give you is a migration which adds a nullable field and starts setting it for new rows. We can worry about the existing rows later in a data migration that updates them in batches.
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.
@rowanseymour ah cool, makes sense, will update this PR with the above
@@ -1948,6 +1948,7 @@ def test_model(self): | |||
schedule=Schedule.create_schedule(self.org, self.admin, timezone.now(), Schedule.REPEAT_MONTHLY), | |||
) | |||
self.assertEqual("I", broadcast1.status) | |||
self.assertEqual(True, broadcast1.is_active) |
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.
don't forget there's a self.assertTrue(..)
No description provided.