
    `jy                    \    d Z ddlmZ ddlZddlmZ dZd Z G d dej                        Zy)	u  Phase 2 — Backfill idswh on all existing GuestStay rows.

Uses uuid.uuid4().hex directly (not the model's save() method) so the
migration is self-contained and does not depend on application code that
may change in the future.

Processes rows in batches of 500 to avoid long-running transactions on
large tables.

Reverse: noop — idswh values are permanent; rolling back the migration
would drop the column anyway (handled by 0010's reverse).
    )annotationsN)
migrationsi  c                   | j                  dd      }t        |j                  j                  d      j	                  dd            }t        dt        |      t              D ]q  }|||t        z    }|j                  j                  |      }|D ]%  }t        j                         j                  |_        ' |j                  j                  |d	g       s y )
Nguests	GuestStayT)idswh__isnullpk)flatr   )pk__inidswh)	get_modellistobjectsfiltervalues_listrangelen_BATCH_SIZEuuiduuid4hexr   bulk_update)appsschema_editorr   pksbatch_start	batch_pksstaysstays           ;/backend/guests/migrations/0011_gueststay_backfill_idswh.pybackfill_idswhr!      s    x5I   t 4@@D@QC
 QC+6kK&?@	!!((	(:D))DJ %%egY7 7    c                  d    e Zd ZdgZ ej
                  eej
                  j                        gZy)	Migration)r   0010_gueststay)reverse_codeN)	__name__
__module____qualname__dependenciesr   	RunPythonr!   noop
operations r"   r    r$   r$   (   s5     	%L
 	
^*:N:N:S:STJr"   r$   )	__doc__
__future__r   r   	django.dbr   r   r!   r$   r.   r"   r    <module>r2      s3    #    8"
$$ r"   