Skip to content

Commit

Permalink
Cleaned up database migration for 2.1 update
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayles committed Jan 3, 2019
1 parent ecde6af commit 5a130a9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
22 changes: 22 additions & 0 deletions nadine/management/commands/migrate_21.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

from datetime import datetime

from django.core.management.base import BaseCommand
from django.utils.timezone import localtime, now

from nadine.models.billing import UserBill

class Command(BaseCommand):
requires_system_checks = True
help = "Runs the 2.1 migrations."

def handle(self, *args, **options):
today = localtime(now()).date()

print("Updating UserBill caches... (this can take awhile)")
for bill in UserBill.objects.all():
bill.update_cached_totals()
bill.delete()


# Copyright 2018 Office Nomads LLC (http://officenomads.com/) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
import django.db.models.deletion


def forward(apps, schema_editor):
# We can't do this in migration space
# UserBill = apps.get_model("nadine", "UserBill")
# for bill in UserBill.objects.all():
# bill.update_cached_totals()
print()
print(" NOTE: After the migration run './manage.py migrate_21'")


class Migration(migrations.Migration):

dependencies = [
Expand Down Expand Up @@ -33,4 +42,27 @@ class Migration(migrations.Migration):
name='tax_rate',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='nadine.TaxRate'),
),
migrations.AddField(
model_name='userbill',
name='cached_total_amount',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7),
),
migrations.AddField(
model_name='userbill',
name='cached_total_owed',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7),
),
migrations.AddField(
model_name='userbill',
name='cached_total_paid',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7),
),
migrations.AddField(
model_name='userbill',
name='cached_total_tax_amount',
field=models.DecimalField(decimal_places=2, default=0, max_digits=7),
),

migrations.RunPython(forward, migrations.RunPython.noop),

]
33 changes: 0 additions & 33 deletions nadine/migrations/0036_auto_20180601_2026.py

This file was deleted.

0 comments on commit 5a130a9

Please sign in to comment.