HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python38/lib/python3.8/site-packages/peewee_migrate/__pycache__/router.cpython-38.pyc
U

ՙ_�	@sddlZddlZddlmZddlmZddlZddlZddl	m	Z	ddl
mZmZddl
mZmZddlmZmZddlmZe�d	ej�Zej�e��d
�Zdd�Zeej�ej�ej�e ��d
���Z!e!�"�Z#W5QRXGdd�de$�Z%Gdd�de%�Z&Gdd�de%�Z'dS)�N)�
import_module)�
ModuleType)�cached_property)�LOGGER�MigrateHistory)�	diff_many�NEWLINE)�string_types�exec_in)�Migratorz\s+$�
migrationscCsdS�N�)�m�drr�F/opt/alt/python38/lib/python3.8/site-packages/peewee_migrate/router.py�<lambda>�rztemplate.txtc@s�eZdZdZdefdd�Zedd��Zedd��Z	d dd�Z
d!dd�Zdd�Zedd��Z
edd��Zedd��Zd"dd�Zd#dd�Zdd�ZdS)$�
BaseRouterzAbstract base class for router.ZmigratehistorycCs6||_||_||_t|jtjtjf�s2td|��dS)NzInvalid database: %s)�database�
migrate_table�logger�
isinstance�pwZDatabaseZProxy�RuntimeError)�selfrrrrrr�__init__s
zBaseRouter.__init__cCs"|jtj_|jtj_t�d�tS)z+Ensure that migrations has prepared to run.T)rr�_metarZdb_tableZcreate_table�rrrr�model"s


zBaseRouter.modelcCst�dSr
��NotImplementedErrorrrrr�todo+szBaseRouter.todo�autoFc	sPd}}��r"t�t�rHzt���Wn"tk
rF|j�d��YSXt�t�rvttdd��fdd�t	��D����|j
D]}|�||j�q|�}t|jj
���}t|||jd�}|s�|j�d�Stt�d	�|��d
��}t�d
|�}t|||jdd�}tt�d	�|��d
��}t�d
|�}|j�d
|�|�|||�}|j�d|�|S)�Create a migration.�zCan't import models module: %scSst|t�ot|tj�Sr
)r�type�
issubclassrZModel)rrrrr;rz#BaseRouter.create.<locals>.<lambda>c3s|]}t�|�VqdSr
)�getattr)�.0r�r#rr�	<genexpr><sz$BaseRouter.create.<locals>.<genexpr>)�migratorzNo changes found.z

�
T)r,�reversezCreating migration "%s"zMigration created %s)rr	r�ImportErrorr�errorr�list�filter�dir�diff�run_oner,Zorm�valuesr�warnr�join�split�CLEAN_RE�sub�info�_create)	r�namer#�migrate�rollbackZ	migrationZmodels1Zmodels2�pathrr*r�create/s8

�
zBaseRouter.creater%cCst�dSr
r )rr>r?r@rrrr=TszBaseRouter._createcCst�dSr
r )rr>rrr�readWszBaseRouter.readcCsdd�|j��D�S)zScan migrations in database.cSsg|]
}|j�qSr�r>)r)�mmrrr�
<listcomp>]sz#BaseRouter.done.<locals>.<listcomp>)r�selectrrrr�doneZszBaseRouter.donecst|j���fdd�|jD�S)z'Calculate difference between fs and db.csg|]}|�kr|�qSrr)r)r>�rHrrrFcsz#BaseRouter.diff.<locals>.<listcomp>)�setrHr"rrrIrr4_s
zBaseRouter.diffcCs&t|j�}|jD]}|�||�q|S)z2Create migrator and setup it with fake migrations.)rrrHr5)rr,r>rrrr,es

zBaseRouter.migratorTc	
Cst�z.|�|�\}}|r�t�d��,t�d��|||j|d�W5QRXW5QRX|rr|jj|d�|j�d|�|��|WS|j�d|�|j�	���|s�|||j|d�|�
�|jj|d�|j�d|�nP|j�d|�|||j|d�|�
�|j���|jj
|k���|j�d|�W5QRXWn>tk
�rn}z|j��|j�d	|��W5d
}~XYnXd
S)zRun a migration.zpeewee.Model.selectzpeewee.Query._execute)�fakerDzDone %szRunning "%s"zRolling back %szRolled back %szMigration failed: %sN)rC�mock�patchrrrBrr<�cleanZtransaction�run�delete�wherer>�execute�	Exceptionr@�	exception)	rr>r,rKZ	downgrade�forcer?r@�excrrrr5ms6$
zBaseRouter.run_oneNcCsj|j�d�g}|j}|s*|j�d�|S|j}|D]0}|j||||d�|�|�|r4||kr4qfq4|S)zRun migrations.zStarting migrationszThere is nothing to migrate)rKrU)rr<r4r,r5�append)rr>rKrHr4r,ZmnamerrrrO�s
zBaseRouter.runcCsV|��}|j}|std��||dkr.td��|j}|�||dd�|j�d|�dS)NzNo migrations are found.���z$Only last migration can be canceled.FTzDowngraded migration: %s)�striprHrr,r5rr7)rr>rHr,rrrr@�szBaseRouter.rollback)r#F)r%r%)TFF)NF)�__name__�
__module__�__qualname__�__doc__rrrr�propertyr"rBr=rCrHr4r,r5rOr@rrrrrs$


%




$
rcsHeZdZe�d�Zef�fdd�	Zedd��Z	ddd�Z
d	d
�Z�ZS)�Routerz[\d]{3}_[^\.]+\.py$cstt|�j|f|�||_dSr
)�superr_r�migrate_dir)rrra�kwargs��	__class__rrr�szRouter.__init__csHtj��j�s*�j�d�j�t��j�t�fdd�t��j�D��S)zScan migrations in file system.z'Migration directory: %s does not exist.c3s,|]$}�j�|�rd�|dd��VqdS)r%N���)�filemask�matchr8)r)�frrrr+�szRouter.todo.<locals>.<genexpr>)	�osrA�existsrarr7�makedirs�sorted�listdirrrrrr"�s
�zRouter.todor%c	Csbt|j�}d�|d�}||d}tj�|j|�}t|d��}|�t	j||d��W5QRX|S)r$z{:03}_��.py�w)r?r@)
�lenr"�formatrirAr8ra�open�write�MIGRATE_TEMPLATE)rr>r?r@�num�prefixrArhrrrr=�s
zRouter._createc
Cs^ttj�|j|d���<}|��}i}t||�|�dt�|�dt�fW5QR�SQRXdS)zRead migration from file.ror?r@N)	rsrirAr8rarCr
�get�VOID)rr>rh�codeZscoperrrrC�s

zRouter.read)r%r%)
rZr[r\�re�compilerf�MIGRATE_DIRrr^r"r=rC�
__classcell__rrrcrr_�s


r_cs&eZdZd�fdd�	Zdd�Z�ZS)�ModuleRouterrcs0tt|�j|f|�t|t�r&t|�}||_dSr
)r`rrrr	r�migrate_module)rrr�rbrcrrr�s
zModuleRouter.__init__cCs$t|j|�}t|dt�t|dt�fS)Nr?r@)r(r�ry)rr>�modrrrrC�szModuleRouter.read)r)rZr[r\rrCr~rrrcrr�sr)(rir{�	importlibr�typesrrLZpeeweerr�peewee_migraterrZpeewee_migrate.autorrZpeewee_migrate.compatr	r
Zpeewee_migrate.migratorrr|�Mr:rAr8�getcwdr}ryrs�abspath�dirname�__file__�trCru�objectrr_rrrrr�<module>s&$%