fecgov / fecfile-web-api

Back-end API for FECfile application
Other
8 stars 2 forks source link

Address mismatched model and migration for cash_on_hand_yearly #1184

Open exalate-issue-sync[bot] opened 1 week ago

exalate-issue-sync[bot] commented 1 week ago

Create a migration that addresses the mismatch.

QA Notes

null

DEV Notes

The model definition has cash_on_hand and year as non-nullable. The initial migration has them as nullable. Because the initial migration has already been run, we can’t just use AlterField in a new migration. We’ll need to do a swap where we put the values into a non-nullable placeholder, remove the old cash_on_hand and year columns, then add new ones with the correct configuration.

The placeholder columns will need to have default values for the theoretical scenario where the original columns are null. Practically, there will be none that are null, but this step ensures the schema updates will work.

Design

null

See full ticket and images here: FECFILE-1765

exalate-issue-sync[bot] commented 8 hours ago

Laura Beaufort commented: After talking to [~accountid:712020:2a1493e5-adee-45bd-b27e-868a5c8d3f62] I think we can use the {{preserve_default=False}} field to achieve this. I’ll verify this locally.

[https://docs.djangoproject.com/en/5.1/ref/migration-operations/#alterfield|https://docs.djangoproject.com/en/5.1/ref/migration-operations/#alterfield|smart-link]

{noformat}# Generated by Django 5.1.1 on 2024-11-14 21:49

from django.db import migrations, models

class Migration(migrations.Migration):

dependencies = [
    ('cash_on_hand', '0001_initial'),
]

operations = [
    migrations.AlterField(
        model_name='cashonhandyearly',
        name='cash_on_hand',
        field=models.DecimalField(decimal_places=2, default=0, max_digits=11),
        preserve_default=False,
    ),
    migrations.AlterField(
        model_name='cashonhandyearly',
        name='year',
        field=models.TextField(default=2020, unique=True),
        preserve_default=False,
    ),
]{noformat}
exalate-issue-sync[bot] commented 8 hours ago

Laura Beaufort commented: I also verified on dev/stage/test that none of these fields are {{NULL}}:

select count(*) from cash_on_hand_yearly where cash_on_hand is null or year is null;# dev: 0

stage: 0

test: 0