Viewing File: /opt/alt/python38/lib/python3.8/site-packages/peewee_migrate/__pycache__/router.cpython-38.pyc

U

p_	@sddlZddlZddlmZddlmZddlZddlZddl	m	Z	ddl
mZmZddl
mZmZddlmZmZddlmZed	ejZejed
ZddZeejejeje d
Z!e!"Z#W5QRXGddde$Z%Gddde%Z&Gddde%Z'dS)N)
import_module)
ModuleType)cached_property)LOGGERMigrateHistory)	diff_manyNEWLINE)string_typesexec_in)Migratorz\s+$
migrationscCsdSN)mdrr
/router.py<lambda>rztemplate.txtc@seZdZdZdefddZeddZeddZ	d ddZ
d!ddZddZeddZ
eddZeddZd"ddZd#ddZddZdS)$
BaseRouterzAbstract base class for router.ZmigratehistorycCs6||_||_||_t|jtjtjfs2td|dS)NzInvalid database: %s)database
migrate_tablelogger
isinstancepwZDatabaseZProxyRuntimeError)selfrrrrrr__init__s
zBaseRouter.__init__cCs"|jtj_|jtj_tdtS)z+Ensure that migrations has prepared to run.T)rrZ_metarZdb_tableZcreate_tablerrrrmodel"s


zBaseRouter.modelcCstdSr
NotImplementedErrorrrrrtodo+szBaseRouter.todoautoFc	sPd}}r"ttrHztWn"tk
rF|jdYSXttrvttddfddt	D|j
D]}|||jq|}t|jj
}t|||jd}|s|jdSttd	|d
}td
|}t|||jdd}ttd	|d
}td
|}|jd
|||||}|jd||S)Create a migration.zCan't import models module: %scSst|tot|tjSr
)rtype
issubclassrZModel)rrrrr;rz#BaseRouter.create.<locals>.<lambda>c3s|]}t|VqdSr
)getattr).0rr"rr	<genexpr><sz$BaseRouter.create.<locals>.<genexpr>)migratorzNo changes found.z


T)r+reversezCreating migration "%s"zMigration created %s)rr	rImportErrorrerrorrlistfilterdirdiffrun_oner+ZormvaluesrwarnrjoinsplitCLEAN_REsubinfo_create)	rnamer"migraterollbackZ	migrationZmodels1Zmodels2pathrr)rcreate/s8


zBaseRouter.creater$cCstdSr
r)rr=r>r?rrrr<TszBaseRouter._createcCstdSr
r)rr=rrrreadWszBaseRouter.readcCsdd|jDS)zScan migrations in database.cSsg|]
}|jqSrr=)r(Zmmrrr
<listcomp>]sz#BaseRouter.done.<locals>.<listcomp>)rZselectrrrrdoneZszBaseRouter.donecst|jfdd|jDS)z'Calculate difference between fs and db.csg|]}|kr|qSrr)r(r=rErrrDcsz#BaseRouter.diff.<locals>.<listcomp>)setrEr!rrrFrr3_s
zBaseRouter.diffcCs&t|j}|jD]}|||q|S)z2Create migrator and setup it with fake migrations.)rrrEr4)rr+r=rrrr+es

zBaseRouter.migratorTc	
Cstz.||\}}|rtd,td|||j|dW5QRXW5QRX|rr|jj|d|jd|||WS|jd||j	|s|||j|d|
|jj|d|jd|nP|jd||||j|d|
|j|jj
|k|jd|W5QRXWn>tk
rn}z|j|jd	|W5d
}~XYnXd
S)zRun a migration.zpeewee.Model.selectzpeewee.Query._execute)fakerCzDone %szRunning "%s"zRolling back %szRolled back %szMigration failed: %sN)rBmockZpatchrrrArr;ZcleanZtransactionrundeletewherer=Zexecute	Exceptionr?Z	exception)	rr=r+rHZ	downgradeforcer>r?excrrrr4ms6$
zBaseRouter.run_oneNcCsj|jdg}|j}|s*|jd|S|j}|D]0}|j||||d|||r4||kr4qfq4|S)zRun migrations.zStarting migrationszThere is nothing to migrate)rHrN)rr;r3r+r4append)rr=rHrEr3r+ZmnamerrrrJs
zBaseRouter.runcCsV|}|j}|std||dkr.td|j}|||dd|jd|dS)NzNo migrations are found.z$Only last migration can be canceled.FTzDowngraded migration: %s)striprErr+r4rr6)rr=rEr+rrrr?szBaseRouter.rollback)r"F)r$r$)TFF)NF)__name__
__module____qualname____doc__rrrrpropertyr!rAr<rBrEr3r+r4rJr?rrrrrs$


%




$
rcsHeZdZedZeffdd	ZeddZ	dddZ
d	d
ZZS)Routerz[\d]{3}_[^\.]+\.py$cstt|j|f|||_dSr
)superrXrmigrate_dir)rrrZkwargs	__class__rrrszRouter.__init__csHtjjs*jdjtjtfddtjDS)zScan migrations in file system.z'Migration directory: %s does not exist.c3s,|]$}j|rd|ddVqdS)r$N)filemaskmatchr7)r(frrrr*szRouter.todo.<locals>.<genexpr>)	osr@existsrZrr6makedirssortedlistdirrrrrr!s
zRouter.todor$c	Csbt|j}d|d}||d}tj|j|}t|d}|t	j||dW5QRX|S)r#z{:03}_.pyw)r>r?)
lenr!formatrbr@r7rZopenwriteMIGRATE_TEMPLATE)rr=r>r?Znumprefixr@rarrrr<s
zRouter._createc
Cs^ttj|j|d<}|}i}t|||dt|dtfW5QRSQRXdS)zRead migration from file.rhr>r?N)	rlrbr@r7rZrBr
getVOID)rr=racodeZscoperrrrBs

zRouter.read)r$r$)
rSrTrUrecompiler_MIGRATE_DIRrrWr!r<rB
__classcell__rrr\rrXs


rXcs&eZdZdfdd	ZddZZS)ModuleRouterrcs0tt|j|f|t|tr&t|}||_dSr
)rYrwrrr	rmigrate_module)rrrxr[r\rrrs
zModuleRouter.__init__cCs$t|j|}t|dtt|dtfS)Nr>r?)r'rxrq)rr=modrrrrBszModuleRouter.read)r)rSrTrUrrBrvrrr\rrwsrw)(rbrs	importlibrtypesrrIZpeeweerrZpeewee_migraterrZpeewee_migrate.autorrZpeewee_migrate.compatr	r
Zpeewee_migrate.migratorrrtMr9r@r7getcwdrurqrlabspathdirname__file__trBrnobjectrrXrwrrrr<module>s&$%
Back to Directory File Manager