# Generated by Django 4.2.28 on 2026-05-07 15:25

import django.db.models.deletion
import pgtrigger.compiler
import pgtrigger.migrations
from django.db import migrations, models


class Migration(migrations.Migration):
    dependencies = [
        ('db', '0056_db_token_valid_type'),
    ]

    operations = [
        migrations.CreateModel(
            name='FileStoreJournal',
            fields=[
                (
                    'id',
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name='ID',
                    ),
                ),
                ('size_change', models.BigIntegerField()),
            ],
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name='fileinstore',
            name='db_fileinstore_total_size_insert',
        ),
        pgtrigger.migrations.RemoveTrigger(
            model_name='fileinstore',
            name='db_fileinstore_total_size_delete',
        ),
        pgtrigger.migrations.AddTrigger(
            model_name='fileinstore',
            trigger=pgtrigger.compiler.Trigger(
                name='db_fileinstore_total_size_insert',
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO db_filestorejournal (store_id, size_change) SELECT NEW.store_id, db_file.size FROM db_file WHERE db_file.id = NEW.file_id; RETURN NULL;',
                    hash='a516ca0f597081f2a76a685d1bd18d4135cac392',
                    operation='INSERT',
                    pgid='pgtrigger_db_fileinstore_total_size_insert_8cd7f',
                    table='db_fileinstore',
                    when='AFTER',
                ),
            ),
        ),
        pgtrigger.migrations.AddTrigger(
            model_name='fileinstore',
            trigger=pgtrigger.compiler.Trigger(
                name='db_fileinstore_total_size_delete',
                sql=pgtrigger.compiler.UpsertTriggerSql(
                    func='INSERT INTO db_filestorejournal (store_id, size_change) SELECT OLD.store_id, -db_file.size FROM db_file WHERE db_file.id = OLD.file_id; RETURN NULL;',
                    hash='c9a8d12ebaaf3f0cea64a0334b6f6a732588f2d3',
                    operation='DELETE',
                    pgid='pgtrigger_db_fileinstore_total_size_delete_07c98',
                    table='db_fileinstore',
                    when='AFTER',
                ),
            ),
        ),
        migrations.AddField(
            model_name='filestorejournal',
            name='store',
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name='journal_entries',
                to='db.filestore',
            ),
        ),
    ]
