Viewing File: /opt/alt/python35/lib/python3.5/site-packages/peewee_migrate/__pycache__/router.cpython-35.pyc



]@s}ddlZddlZddlmZddlmZddlZddlZddl	m	Z	ddl
mZmZddl
mZmZddlmZmZddlmZejd	ejZejjejd
ZddZeejjejjejje d
Z!e!j"Z#WdQRXGddde$Z%Gddde%Z&Gddde%Z'dS)N)
import_module)
ModuleType)cached_property)LOGGERMigrateHistory)	diff_manyNEWLINE)string_typesexec_in)Migratorz\s+$
migrationscCsdS)N)mdr
r

/router.py<lambda>srztemplate.txtc@seZdZdZdeddZeddZeddZ	d	d
ddZ
d
d
ddZddZeddZ
eddZeddZdd
d
ddZdd
ddZddZdS) 
BaseRouterzAbstract base class for router.ZmigratehistorycCsM||_||_||_t|jtjtjfsItd|dS)NzInvalid database: %s)database
migrate_tablelogger
isinstancepwZDatabaseZProxyRuntimeError)selfrrrr
r
r__init__s
			zBaseRouter.__init__cCs/|jtj_|jtj_tjdtS)z+Ensure that migrations has prepared to run.T)rrZ_metarZdb_tableZcreate_table)rr
r
rmodel"s
zBaseRouter.modelcCs
tdS)N)NotImplementedError)rr
r
rtodo+szBaseRouter.todoautoFc	sd}}rttrWytWn%tk
rV|jjdSYnXttrttddfddt	Dx$|j
D]}|j||jqW}t|jj
j}t||d|j}|s
|jjdSttjd	j|jd
}tjd
|}t||d|jdd}ttjd	j|jd
}tjd
|}|jjd
||j|||}|jjd||S)zCreate a migration.zCan't import models module: %scSst|tot|tjS)N)rtype
issubclassrZModel)rr
r
rr;sz#BaseRouter.create.<locals>.<lambda>c3s|]}t|VqdS)N)getattr).0r)rr
r	<genexpr><sz$BaseRouter.create.<locals>.<genexpr>migratorzNo changes found.z


reverseTzCreating migration "%s"zMigration created %s)rr	rImportErrorrerrorrlistfilterdirdiffrun_oner%ZormvaluesrwarnrjoinsplitCLEAN_REsubinfo_create)	rnamermigraterollbackZ	migrationZmodels1Zmodels2pathr
)rrcreate/s6

	%%%zBaseRouter.creatercCs
tdS)N)r)rr7r8r9r
r
rr6TszBaseRouter._createcCs
tdS)N)r)rr7r
r
rreadWszBaseRouter.readcCsdd|jjDS)zScan migrations in database.cSsg|]}|jqSr
)r7)r#Zmmr
r
r
<listcomp>]s	z#BaseRouter.done.<locals>.<listcomp>)rselect)rr
r
rdoneZszBaseRouter.donecs)t|jfdd|jDS)z'Calculate difference between fs and db.cs"g|]}|kr|qSr
r
)r#r7)r?r
rr=cs	z#BaseRouter.diff.<locals>.<listcomp>)setr?r)rr
)r?rr-_szBaseRouter.diffcCs7t|j}x!|jD]}|j||qW|S)z2Create migrator and setup it with fake migrations.)rrr?r.)rr%r7r
r
rr%eszBaseRouter.migratorTc	 Csy|j|\}}|rtjd2tjd|||jd|WdQRXWdQRX|r|jjd||jjd||j|S|jjd||jj	|s|||jd||j
|jjd||jjd|nn|jjd||||jd||j
|jjj|jj
|kj|jjd	|WdQRXWnHtk
r}z(|jj|jjd
|WYdd}~XnXdS)zRun a migration.zpeewee.Model.selectzpeewee.Query._executefakeNr7zDone %szRunning "%s"zRolling back %szRolled back %szMigration failed: %s)r<mockZpatchrrr;rr5ZcleanZtransactionrundeleteZwherer7Zexecute	Exceptionr9	exception)	rr7r%rAZ	downgradeforcer8r9excr
r
rr.ms6$


(
zBaseRouter.run_oneNcCs|jjdg}|j}|s9|jjd|S|j}xJ|D]B}|j||d|d||j||rI||krIPqIW|S)zRun migrations.zStarting migrationszThere is nothing to migraterArG)rr5r-r%r.append)rr7rAr?r-r%Zmnamer
r
rrCs		

zBaseRouter.runcCsy|j}|j}|s'td||dkrCtd|j}|j||dd|jjd|dS)NzNo migrations are found.z$Only last migration can be canceled.FTzDowngraded migration: %s)stripr?rr%r.rr0)rr7r?r%r
r
rr9s		zBaseRouter.rollback)__name__
__module____qualname____doc__rrrrpropertyrr;r6r<r?r-r%r.rCr9r
r
r
rrs	%$rcsdeZdZejdZefddZeddZ	ddddZ
d	d
ZS)Routerz[\d]{3}_[^\.]+\.py$cs&tt|j||||_dS)N)superrRrmigrate_dir)rrrTkwargs)	__class__r
rrszRouter.__init__csdtjjjs;jjdjtjjtfddtjjDS)zScan migrations in file system.z'Migration directory: %s does not exist.c3s:|]0}jj|rdj|ddVqdS)rN)filemaskmatchr1)r#f)rr
rr$szRouter.todo.<locals>.<genexpr>)	osr:existsrTrr0makedirssortedlistdir)rr
)rrrs
zRouter.todorc
Cst|j}dj|d}||d}tjj|j|}t|d&}|jt	jd|d|WdQRX|S)zCreate a migration.z{:03}_rJz.pywr8r9N)
lenrformatr\r:r1rTopenwriteMIGRATE_TEMPLATE)rr7r8r9numprefixr:r[r
r
rr6s&zRouter._createcCsqttjj|j|dH}|j}i}t|||jdt|jdtfSWdQRXdS)zRead migration from file.z.pyr8r9N)	rdr\r:r1rTr<r
getVOID)rr7r[codeZscoper
r
rr<s
%
zRouter.read)rMrNrOrecompilerYMIGRATE_DIRrrQrr6r<r
r
)rVrrRs
	rRcs1eZdZdfddZddZS)ModuleRouterrcsAtt|j||t|tr4t|}||_dS)N)rSrorrr	rmigrate_module)rrrprU)rVr
rrszModuleRouter.__init__cCs4t|j|}t|dtt|dtfS)Nr8r9)r"rprj)rr7modr
r
rr<szModuleRouter.read)rMrNrOrr<r
r
)rVrrosro)(r\rl	importlibrtypesrrBZpeeweerrZpeewee_migraterrZpeewee_migrate.autorrZpeewee_migrate.compatr	r
Zpeewee_migrate.migratorrrmMr3r:r1getcwdrnrjrdabspathdirname__file__tr<rfobjectrrRror
r
r
r<module>s$6%
Back to Directory File Manager