
    `j                    T    d Z ddlmZ ddlmZmZ d Z G d dej                        Zy)u  Phase 3 — Enforce idswh uniqueness and remove nullability.

This migration is safe to run only AFTER 0011 has completed and all
GuestStay rows have been backfilled (idswh IS NOT NULL for every row).

The AlterField operation:
- Adds the UNIQUE constraint to the database column.
- Removes NULL from the column definition.

Pre-flight check: the migration will fail fast if any NULL values remain,
preventing a silent partial constraint.
    )annotations)
migrationsmodelsc                    | j                  dd      }|j                  j                  d      j                         }|dkD  rt	        d| d      y)	zAbort if any GuestStay row still has a NULL idswh.

    This guard prevents the UNIQUE + NOT NULL constraint from being applied
    to an incompletely backfilled table, which would cause a cryptic DB error.
    guests	GuestStayT)idswh__isnullr   z!Cannot enforce idswh uniqueness: zq GuestStay row(s) still have NULL idswh. Run migration 0011 first and verify the backfill completed successfully.N)	get_modelobjectsfiltercountRuntimeError)appsschema_editorr   
null_counts       9/backend/guests/migrations/0012_gueststay_idswh_unique.pyassert_no_nullsr      s`     x5I"")))=CCEJA~/
| <3 4
 	
     c                      e Zd ZdgZ ej
                  eej
                  j                         ej                  dd e	j                  dddddd	      
      gZy)	Migration)r   0011_gueststay_backfill_idswh)reverse_code	gueststayidswhTFzPermanent, globally unique regulatory identity token. Generated once at creation. Never recomputed, never overwritten. Used as the canonical identifier across C59, ISTAT, Ross 1000, and Alloggiati Web exports.@   )db_indexeditable	help_text
max_lengthnullunique)
model_namenamefieldN)__name__
__module____qualname__dependenciesr   	RunPythonr   noop
AlterFieldr   	CharField
operations r   r   r   r   "   ss     	4L 	
_:;O;O;T;TU 	
""&""2
 	
Jr   r   N)__doc__
__future__r   	django.dbr   r   r   r   r.   r   r   <module>r2      s)    # (
 
$$ r   