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__/migrator.cpython-38.pyc
U

/�Xp*�@s�ddlZddlmZmZmZm	Z
mZmZm
Z
mZmZmZmZmZddlmZGdd�de�ZGdd�dee�ZGdd	�d	ee�ZGd
d�dee
�Z	dd
�ZGdd�de�ZdS)�N)�
MySQLMigrator�PostgresqlMigrator�SchemaMigrator�SqliteMigrator�	Operation�SQL�Entity�Clause�PostgresqlDatabase�	operation�SqliteDatabase�
MySQLDatabase)�LOGGERcsZeZdZdZe�fdd��Zddd�Zedd��Zd	d
�Z	edd��Z
ed
d��Z�ZS)rzImplement migrations.csFt|t�rt|�St|t�r$t|�St|t�r6t|�Stt|��	|�S)zInitialize migrator by db.)
�
isinstancer
rrrr
r�superr�
from_database)�cls�database��	__class__��H/opt/alt/python38/lib/python3.8/site-packages/peewee_migrate/migrator.pyrs


zSchemaMigrator.from_databaseTcs��fdd�S)Ncs�j�d�S)N��cascade��
drop_tabler�r�modelrr�<lambda>�z+SchemaMigrator.drop_table.<locals>.<lambda>r��selfrrrrrrszSchemaMigrator.drop_tablecCs.|�|||�g}|js*|�|�||�g�|S)zChange column.)�alter_change_column�null�extend�add_not_null)r!�table�column_name�fieldZ
operationsrrr�
change_columnszSchemaMigrator.change_columncCs>|jd}|_|j���|�}||_ttd�t|�td�|�S)�Support change columns.T�ALTER TABLEzALTER COLUMN)r#r�compiler�field_definitionr	rr)r!r&�columnr(�
field_null�field_clauserrrr"'sz"SchemaMigrator.alter_change_columncGstt|f|���S)zExecute raw SQL.)r	r�r!�sql�paramsrrrr2.szSchemaMigrator.sqlcCsn|jd}|_||_|j���|�}||_td�t|�td�|g}t|tj	�r`|�
|�|��n||_t
|�S)zKeep fieldname unchanged.Tr+z
ADD COLUMN)r#�	db_columnrr,r-rrr�pw�ForeignKeyFieldr$Zget_inline_fk_sql�namer	)r!r&r'r(r/r0�partsrrr�alter_add_column3s�zSchemaMigrator.alter_add_column)T)
�__name__�
__module__�__qualname__�__doc__�classmethodrrrr)r"r2r9�
__classcell__rrrrr
s



rcs eZdZdZ�fdd�Z�ZS)rz Support the migrations in MySQL.cs4tt|��|||�}|jd}|j�dtd��|S�r*����ZTYPE)rrr"�nodes�insertr�r!r&r'r(�clauser0rrrr"Ks
z!MySQLMigrator.alter_change_column�r:r;r<r=r"r?rrrrrGsrcs eZdZdZ�fdd�Z�ZS)rz%Support the migrations in postgresql.cs4tt|��|||�}|jd}|j�dtd��|Sr@)rrr"rCrDrrErrrr"Ws
z&PostgresqlMigrator.alter_change_columnrGrrrrrSsrc@s"eZdZdZddd�Zdd�ZdS)	rz!Support the migrations in sqlite.Tcs�fdd�S)z0SQLite doesnt support cascade syntax by default.cs�jdd�S)NFrrr�rrrrerz+SqliteMigrator.drop_table.<locals>.<lambda>rr rrHrrcszSqliteMigrator.drop_tablecs��fdd�}��|||�S)r*cs&�j��}|���}|�|�\}}|S�N)rr,r-Z
parse_node)r'Z
column_defr,rFr2�_�r(r!rr�_changeis

z3SqliteMigrator.alter_change_column.<locals>._change)Z_update_column)r!r&r.r(rLrrKrr"gsz"SqliteMigrator.alter_change_columnN)T)r:r;r<r=rr"rrrrr_s
rcs�fdd�}|S)zConvert string to model class.cs4t|t�r"�||j|f|�|�S�||f|�|�SrI)r�str�orm)�migratorr�args�kwargs��methodrr�wrapperss
zget_model.<locals>.wrapperr)rSrTrrRr�	get_modelqsrUc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	e	Z
ed(dd��ZeZ
edd��ZeZedd��ZeZedd��ZeZdd�Zedd��ZeZedd��Zedd��Zedd ��Zed!d"��Zed#d$��Zed%d&��Zd'S))�MigratorzProvide migrations.cCs:t|tj�r|j}||_t�|_t�|_t	�
|j�|_dS)zInitialize the migrator.N)rr5ZProxy�objr�dictrN�list�opsrrrO)r!rrrr�__init__~szMigrator.__init__cCsD|jD]0}t|t�r0t�d|j|j�|��q|�q|��dS)zRun operations.z%s %sN)	rZrrr�inforSrP�run�clean)r!Zopnrrrr]�s


zMigrator.runcs|j����fdd��dS)zRun python code.cs
����SrIrr�rP�funcrQrrr�rz!Migrator.python.<locals>.<lambda>N)rZ�append)r!r`rPrQrr_r�python�szMigrator.pythoncGs|j�|jj|f|���dS)zExecure raw SQL.N)rZrarOr2r1rrrr2�szMigrator.sqlcCst�|_dS)zClean the operations.N)rYrZ)r!rrrr^�szMigrator.cleancCs*||j|jj<|j|j_|j�|j�|S)zUCreate model and table in database.

        >> migrator.create_table(model)
        )rN�_meta�db_tablerrZra�create_table)r!rrrrre�s
zMigrator.create_tableTcCs&|j|jj=|j�|j�||��dS)zaDrop model and table from database.

        >> migrator.drop_table(model, cascade=True)
        N)rNrcrdrZrarOrr rrrr�szMigrator.drop_tablecKsh|��D]Z\}}|�||�|j�|j�|jj|j|��|j	r|j�|jj
|jj|jfdd��q|S)zCreate new fields.T��unique)�items�add_to_classrZrarOZ
add_columnrcrdr4rg�	add_index�r!r�fieldsr7r(rrr�add_columns�s�
zMigrator.add_columnscKsh|��D]Z\}}|�||�|j�|j�|jj|j|��|j	r|j�|jj
|jj|jfdd��q|S)zChange fields.Trf)rhrirZrarOr)rcrdr4rgrjrkrrr�change_columns�s��
zMigrator.change_columnsc	s��fdd�|jj��D�}|�dd�}|D]n}|�||�|jrx|j��}|�|jj	|j
f�}|j�|j
�|jj	|��|j�|j
j|jj	|j
|d��q*|S)zRemove fields from model.csg|]}|j�kr|�qSr)r7)�.0r(��namesrr�
<listcomp>�s
z)Migrator.drop_columns.<locals>.<listcomp>rTr)rcrl�values�pop�
__del_field__rgrr,�
index_namerdr4rZrarO�
drop_indexZdrop_column)	r!rrqrQrlrr(r,rvrrpr�drop_columns�s
�zMigrator.drop_columnscCsF|j�|j�t||j�t|tj�rBt|j|j�|jjj	|j=dS)zDelete field from model.N)
rcZremove_fieldr7�delattrrr5r6Z	rel_modelZrelated_nameZreverse_rel)r!rr(rrrru�s
zMigrator.__del_field__cCs~|jj|}t|tj�r|j}|�||�||_|_|�||�t|tj�r^|jd|_}|j	�
|j�|jj
||��|S)zRename field in model.�_id)rcrlrr5r6r4rur7rirZrarO�
rename_columnrd)r!rZold_name�new_namer(rrrr{�szMigrator.rename_columncCs@|j|jj=||j_||j|jj<|j�|j�|jj|��|S)zRename table in database.)rNrcrdrZrarO�rename_table)r!rr|rrrr}�s
zMigrator.rename_tablecOsz|�dd�}|jj�||f�g}|D]0}|jj�|�}t|tj�rL|d}|�|�q&|j	�|j
j|jj||d��|S)zCreate indexes.rgFrzrf)
rtrc�indexesrarl�getrr5r6rZrOrjrd)r!r�columnsrQrg�columns_�colr(rrrrjszMigrator.add_indexcs�g}�D]0}|jj�|�}t|tj�r.|d}|�|�q|jj�	��
|jj|�}�fdd�|jjD�|j_|j
�|j�|jj|��|S)z
Drop indexes.rzcs g|]\}}�|kr||f�qSrr)ro�colsrJ�r�rrrrsz'Migrator.drop_index.<locals>.<listcomp>)rcrlrrr5r6rarOrr,rvrdr~rZrw)r!rr�r�r�r(rvrr�rrwszMigrator.drop_indexcGs<|D]2}|jj|}d|_|j�|j�|jj|j��q|S)z
Add not null.F)	rcrlr#rZrarOr%rdr4�r!rrqr7r(rrrr%s
zMigrator.add_not_nullcGs<|D]2}|jj|}d|_|j�|j�|jj|j��q|S)zDrop not null.T)	rcrlr#rZrarO�
drop_not_nullrdr4r�rrrr�'s
zMigrator.drop_not_nullcCs>|jj|}||jj|<|_|j�|j�|jj||��|S)zAdd default.)	rcrl�defaults�defaultrZrarOZ
apply_defaultrd)r!rr7r�r(rrr�add_default0szMigrator.add_defaultN)T)r:r;r<r=r[r]rbr2r^reZcreate_modelrUrZremove_modelrmZ
add_fieldsrnZ
change_fieldsrxZ
remove_fieldsrur{Zrename_fieldr}rjrwr%r�r�rrrrrVzsH















rV)Zpeeweer5Zplayhouse.migraterZMqMrZPgMrZScMrZSqMrrrr	r
rrr
�peewee_migraterrU�objectrVrrrr�<module>s8: