
    Vh*                         d dl Z d dlZd dlmZ d dlmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  G d de      Zy)    N)apps)settings)BaseCommandCommandError)run_formatters)DEFAULT_DB_ALIASconnections
migrations)AmbiguityErrorMigrationLoader)SwappableTuple)MigrationOptimizer)MigrationWriter)get_docs_versionc                   "    e Zd ZdZd Zd Zd Zy)CommandzZSquashes an existing set of migrations (from first until specified) into a single new one.c                    |j                  dd       |j                  ddd       |j                  dd	       |j                  d
dd       |j                  ddddd       |j                  dd       |j                  dddd       y )N	app_labelz6App label of the application to squash migrations for.)helpstart_migration_name?zGMigrations will be squashed starting from and including this migration.)nargsr   migration_namez?Migrations will be squashed until and including this migration.z--no-optimize
store_truez/Do not try to optimize the squashed operations.)actionr   z	--noinputz
--no-inputstore_falseinteractivez:Tells Django to NOT prompt the user for input of any kind.)r   destr   z--squashed-namez,Sets the name of the new squashed migration.z--no-headerinclude_headerz:Do not add a header comment to the new squashed migration.)add_argument)selfparsers     `/home/dcms/DCMS/lib/python3.12/site-packages/django/core/management/commands/squashmigrations.pyadd_argumentszCommand.add_arguments   s    I 	 	
 	"	 	 	
 	R 	 	
 	B 	 	

 	 M 	 	
 	? 	 	
 	 !M	 	 	
    c           
         |d   | _         |d   | _        |d   }|d   }|d   }|d   }|d   }|d   }	 t        j                  |       t        t        t                 }	||	j                  vrt        d	|z        | j                  |	||      }
|	j                  j                  |
j                  |
j                  f      D cg c]&  \  }}||
j                  k(  r|	j!                  ||      ( }}}|rP| j                  |	||      }|	j!                  |j                  |j                        }	 |j#                  |      }||d  }| j                   dkD  s| j                  r| j&                  j)                  | j*                  j-                  d             |D ]*  }
| j&                  j)                  d|
j                  z         , | j                  r9d }|r|dvr+t/        d      }|sd}n|d   j1                         }|s&|dvr+|dk7  ry g }t3               }d}|D ]  }|j4                  rt        dt7               z        |j9                  |j:                         |j<                  D ]y  }t?        |t@              rAtB        jD                  |jF                  k(  r|jI                  d       B|jI                  |       T|d   |j                  k7  s|si|jI                  |       { d} |rF| j                   dkD  r4| j&                  j)                  | j*                  j-                  d             |}n| j                   dkD  r4| j&                  j)                  | j*                  j-                  d             tK               }|jM                  ||
j                        }| j                   dkD  rgtO        |      tO        |      k(  r| j&                  j)                  d       n4| j&                  j)                  dtO        |      dtO        |      d       g }|D ]Q  }
|
j4                  r|j9                  |
j4                         +|jQ                  |
j                  |
j                  f       S tS        dtT        jV                  f|||d       }|rN|r'j                  jY                  d!d"      \  }}|d!|}nj                  d#|
j                  } |||      }n&d$|xs d%|
j                  z  z  } |||      }d|_-        t]        ||      }t^        j`                  jc                  |j`                        rt        d&|j                   d'      te        |j`                  d(d)*      5 } | j)                  |jg                                d d d        ti        |j`                  g| jj                  +       | j                   dkD  r| j&                  j)                  | j*                  j-                  d,|j`                  z        d-z          |jl                  r| j&                  j)                  | j*                  j-                  d.      d/z          to        jp                  d0      r5| j&                  j)                  | j*                  js                  d1             y y y y # t        $ r}t        t        |            d }~ww xY wc c}}w # t$        $ r t        d
|d|
d|d      w xY w# 1 sw Y   \xY w)2N	verbosityr   r   r   r   no_optimizesquashed_namer   zLApp '%s' does not have migrations (so squashmigrations on it makes no sense)zThe migration 'z7' cannot be found. Maybe it comes after the migration 'z5'?
Have a look at:
  python manage.py showmigrations z
to debug this issue.r   z%Will squash the following migrations:z - %synzDo you wish to proceed? [y/N] nyTzYou cannot squash squashed migrations! Please transition it to a normal migration first: https://docs.djangoproject.com/en/%s/topics/migrations/#squashing-migrations)__setting__AUTH_USER_MODELFz(Skipping optimization.)zOptimizing...z  No optimizations possible.z  Optimized from z operations to z operations.	Migration)dependencies
operationsreplaces_   
_squashed_z0001_%szsquashed_%sz
Migration z& already exists. Use a different name.wzutf-8)encoding)stderrz!Created new squashed migration %sz
  You should commit this migration but leave the old ones in place;
  the new migration will be used for new installs. Once you are sure
  all instances of the codebase have applied the migrations you squashed,
  you can delete them.zManual porting requiredz
  Your migrations contained functions that must be manually copied over,
  as we could not safely copy their implementation.
  See the comment at the top of the squashed migration for details.blackz]Squashed migration couldn't be formatted using the "black" command. You can call it manually.):r'   r   r   get_app_configLookupErrorr   strr   r	   r   migrated_appsfind_migrationgraphforwards_planr   nameget_migrationindex
ValueErrorstdoutwritestyleMIGRATE_HEADINGinputlowersetr2   r   extendr1   r0   
isinstancer   r   r.   settingaddr   optimizelenappendtyper
   r/   splitinitialr   ospathexistsopen	as_stringr   r8   needs_manual_portingshutilwhichWARNING)!r!   optionsr   r   r   r(   r)   r   errloader	migrationalmnmigrations_to_squashstart_migrationstartstart_indexanswerr1   r0   first_migration
smigration
dependencynew_operations	optimizerr2   subclassprefixr3   rA   new_migrationwriterfhs!                                    r#   handlezCommand.handle>   s    -"=1K(	&'=> !12m,0 !12	)	*
 !-=!>?F000%'01 
 ''	>J	
 !,,44$$inn5 
B Y(((	   R( 
  
  "11	#7O (())?+?+?E
288?';KL'I$ >>A!1!1KK

**+RS 2 <	!!'INN":;<  F$$6"#CDF!!$!'!2 !F$$6 S=
 
u . 	$J""">@P@RS 
 j334(55 1
j.9//:3E3EE$(()KL$((4]j&:&::o $$Z01 $O!	$$ ~~!!!JJ../IJ (N~~!!!$**"<"<_"MN*,I&//
I<O<OPN~~!~&#j/9KK%%&DEKK%%z?C,?A - 	GI!!	 2 23!4!4inn EF		G !!# ,,$
  +0066sA>	"(-8 ,;+?+?P$T95M O1OPD$T95M$(M! !?77>>&++&]//00VW  &++sW5 	)HHV%%'(	)}T[[9>>AKK

**7&++E))
 **!!JJ../HI M  <<(KK%%

**I ) + q  	)s3x((	) 
$  "
 />y)	U h	) 	)s5   Z	 +Z.,Z4  [		Z+Z&&Z+4[[ c                     	 |j                  ||      S # t        $ r t        d|d|d      t        $ r t        d|d|d      w xY w)Nz!More than one migration matches 'z
' in app 'z'. Please be more specific.z"Cannot find a migration matching 'z' from app 'z'.)get_migration_by_prefixr   r   KeyError)r!   ra   r   rA   s       r#   r>   zCommand.find_migration   sa    	11)TBB 	$()5   	$ 	s	    6A
N)__name__
__module____qualname__r   r$   rt   r>    r%   r#   r   r      s    	 	
&
PBr%   r   )rV   r\   django.appsr   django.confr   django.core.management.baser   r   django.core.management.utilsr   	django.dbr   r	   r
   django.db.migrations.loaderr   r   django.db.migrations.migrationr   django.db.migrations.optimizerr   django.db.migrations.writerr   django.utils.versionr   r   r{   r%   r#   <module>r      s:    	     A 7 ? ? G 9 = 7 1{k {r%   