
    9 f                         d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ d	 Z G d
 dej                  Z G d dej                  Zd Zd Zd ZdS )z
Various suggestions around migrations. Disabled by default! Enable with
pylint --load-plugins=pylint_django.checkers.migrations
    N)checkers)suppress_message)compat)BASE_ID)check_messages)is_migrations_modulec                    t          | j        t          j                  sdS | j        j        dk    sdS | j        D ]J}|j        dk    r=t          |j        t          j                  r|j        j        D ]}|j        dk    r  dS KdS )NFAddFieldfielddefaultT)	
isinstancefuncastroid	AttributeattrnamekeywordsargvalueCall)callkeywordfield_keywords      W/var/www/equiseq/venv/lib/python3.11/site-packages/pylint_django/checkers/migrations.py_is_addfield_with_defaultr      s    di!233 u9++u= 	  	 ;'!!j&M&M!
 ")!7     $	11444 2 5    c                   b    e Zd ZdZdZde ddiZg Zi Zd Z	d Z
 ed          d             Zd	S )
NewDbFieldWithDefaultCheckera  
    Looks for migrations which add new model fields and these fields have a
    default value. According to Django docs this may have performance penalties
    especially on large tables:
    https://docs.djangoproject.com/en/2.0/topics/migrations/#postgresql

    The preferred way is to add a new DB column with null=True because it will
    be created instantly and then possibly populate the table with the
    desired default values.
    new-db-field-with-defaultW98)z%s AddField with default valuer   zKUsed when Pylint detects migrations adding new fields with a default value.c                 \    t          |          r| j                            |           d S d S N)r   _migration_modulesappend)selfnodes     r   visit_modulez)NewDbFieldWithDefaultChecker.visit_moduleC   s9    %% 	1#**400000	1 	1r   c                    	 |                                 j        }n#  Y d S xY wt          |          sd S t          |          rD|| j        vr
g | j        |<   || j        |         vr$| j        |                             |           d S d S d S r"   )frameparentr   r   _possible_offencesr$   )r%   r&   modules      r   
visit_callz'NewDbFieldWithDefaultChecker.visit_callG   s    	ZZ\\(FF	FF#F++ 	F$T** 	=T44424'/426:::'/66t<<<<<	= 	= ;:    !c                 p   d }| j                             |d           d}g }| j         D ]E}|j        d                             d          d         }||k    r|}|                    |           F| j                                        D ]+\  }}||v r"|D ]}|                     d|j        |            ,d S )	Nc                     | j         S r"   )pathr&   s    r   _pathz1NewDbFieldWithDefaultChecker.close.<locals>._pathY   s
    9r   T)keyreverse r   
migrationsr   )argsr&   )	r#   sortr1   splitr$   r+   itemsadd_messagename)r%   r3   last_name_spacelatest_migrationsr,   
name_spacenodesr&   s           r   closez"NewDbFieldWithDefaultChecker.closeW   s   	 	 	
 	$$$===
 - 	1 	1FQ--l;;A>J_,,",!((000!4::<< 	_ 	_MFE***! _ _D$$%@v{Y]$^^^^	_ 	_r   N)__name__
__module____qualname____doc__r=   r   msgsr#   r+   r'   r-   r   rB    r   r   r   r   *   s        	 	 'DG 
D 1 1 1= = =  ^/00_ _ 10_ _ _r   r   c                   J    e Zd ZdZde ddiZ ed          d             ZdS ) MissingBackwardsMigrationChecker$missing-backwards-migration-callabler   97)z+Always include backwards migration callablerK   zbAlways include a backwards/reverse callable counterpart so that the migration is not irreversable.c                    	 |                                 j        }n#  Y d S xY wt          |          sd S |j                                                            d          rit          |j                  dk     rS|j        r1|j        D ]}|j	        dk    r d S | 
                    d|           d S | 
                    d|           d S d S d S )N	RunPython   reverse_coderK   r2   )r)   r*   r   r   	as_stringendswithlenr8   r   r   r<   )r%   r&   r,   r   s       r   r-   z+MissingBackwardsMigrationChecker.visit_call|   s    	ZZ\\(FF	FF#F++ 	F9  ))+66 	T3ty>>A;M;M} T#}  G{n44 5  !Gd SSSSS  !Gd SSSSS	T 	T;M;Mr.   N)rC   rD   rE   r=   r   rG   r   r-   rH   r   r   rJ   rJ   q   s^        1D 	G 
D ^:;;T T <;T T Tr   rJ   c                 *    t          | j                  S )a  
    RunPython() migrations receive forward/backwards functions with signature:

        def func(apps, schema_editor):

    which could be unused. This augmentation will suppress all 'unused-argument'
    messages coming from functions in migration modules.
    )r   r*   r2   s    r   is_in_migrationsrU      s      ,,,r   c                     t          | j        j                  }d|v r|                    d           || j        _        d S )Nr7   )listconfig
black_listremove)linternew_black_lists     r   load_configurationr]      sC    &-233N~%%l+++-FMr   c                    |                      t          |                      |                      t          |                      t          j        st          |            t          | t          j        j	        j
        dt                     dS )z.Required method to auto register this checker.zunused-argumentN)register_checkerr   rJ   r   LOAD_CONFIGURATION_SUPPORTEDr]   r   r   	variablesVariablesCheckerleave_functiondefrU   )r[   s    r   registerrd      s    
8@@AAA
<VDDEEE. #6""" +=	    r   )rF   r   pylintr   pylint_plugin_utilsr   pylint_djangor   pylint_django.__pkginfo__r   pylint_django.compatr   pylint_django.utilsr   r   BaseCheckerr   rJ   rU   r]   rd   rH   r   r   <module>rl      s?   
        0 0 0 0 0 0             - - - - - - / / / / / / 4 4 4 4 4 4  *D_ D_ D_ D_ D_8#7 D_ D_ D_NT T T T Tx'; T T T>	- 	- 	-. . .    r   