ProjectFlask/FlaskMigrateExtension/MigrateProjectExtension.py

changeset 34
a91c6a1eb23f
parent 33
c82b296a21ae
child 35
65a377b7a52c
equal deleted inserted replaced
33:c82b296a21ae 34:a91c6a1eb23f
21 21
22 from ..FlaskCommandDialog import FlaskCommandDialog 22 from ..FlaskCommandDialog import FlaskCommandDialog
23 23
24 24
25 # TODO: add a submenu with action for the commands with command options 25 # TODO: add a submenu with action for the commands with command options
26 # TODO: add a submenu to show the created SQL commands (--sql option)
26 class MigrateProject(QObject): 27 class MigrateProject(QObject):
27 """ 28 """
28 Class implementing the flask-migrate project support. 29 Class implementing the flask-migrate project support.
29 """ 30 """
30 def __init__(self, plugin, project, parent=None): 31 def __init__(self, plugin, project, parent=None):
140 self.actions.append(self.migrateCreateAct) 141 self.actions.append(self.migrateCreateAct)
141 142
142 ######################################################### 143 #########################################################
143 ## action to up- and downgrade a databse 144 ## action to up- and downgrade a databse
144 ######################################################### 145 #########################################################
145 # TODO: add action for flask db upgrade 146
147 self.upgradeDatabaseAct = E5Action(
148 self.tr('Upgrade Database'),
149 self.tr('&Upgrade Database'),
150 0, 0,
151 self, 'flask_upgrade_database')
152 self.upgradeDatabaseAct.setStatusTip(self.tr(
153 'Upgrade the database to the current migration'))
154 self.upgradeDatabaseAct.setWhatsThis(self.tr(
155 """<b>Upgrade Database</b>"""
156 """<p>Upgrades the database to the current migration.</p>"""
157 ))
158 self.upgradeDatabaseAct.triggered.connect(
159 self.__upgradeDatabase)
160 self.actions.append(self.upgradeDatabaseAct)
161
146 # TODO: add action for flask db downgrade 162 # TODO: add action for flask db downgrade
163 self.downgradeDatabaseAct = E5Action(
164 self.tr('Downgrade Database'),
165 self.tr('&Downgrade Database'),
166 0, 0,
167 self, 'flask_downgrade_database')
168 self.downgradeDatabaseAct.setStatusTip(self.tr(
169 'Downgrade the database to the previous version'))
170 self.downgradeDatabaseAct.setWhatsThis(self.tr(
171 """<b>Downgrade Database</b>"""
172 """<p>Downgrades the database to the previous version.</p>"""
173 ))
174 self.downgradeDatabaseAct.triggered.connect(
175 self.__downgradeDatabase)
176 self.actions.append(self.downgradeDatabaseAct)
147 177
148 def initMenu(self): 178 def initMenu(self):
149 """ 179 """
150 Public method to initialize the flask-migrate menu. 180 Public method to initialize the flask-migrate menu.
151 181
158 menu.addAction(self.migrateConfigAct) 188 menu.addAction(self.migrateConfigAct)
159 menu.addSeparator() 189 menu.addSeparator()
160 menu.addAction(self.migrateInitAct) 190 menu.addAction(self.migrateInitAct)
161 menu.addSeparator() 191 menu.addSeparator()
162 menu.addAction(self.migrateCreateAct) 192 menu.addAction(self.migrateCreateAct)
193 menu.addSeparator()
194 menu.addAction(self.upgradeDatabaseAct)
195 menu.addAction(self.downgradeDatabaseAct)
163 menu.addSeparator() 196 menu.addSeparator()
164 menu.addAction(self.migrateAvailabilityAct) 197 menu.addAction(self.migrateAvailabilityAct)
165 menu.addAction(self.migrateInstallAct) 198 menu.addAction(self.migrateInstallAct)
166 199
167 return menu 200 return menu
238 @pyqtSlot() 271 @pyqtSlot()
239 def __configureMigrate(self): 272 def __configureMigrate(self):
240 """ 273 """
241 Private slot to show a dialog to edit the migrate configuration. 274 Private slot to show a dialog to edit the migrate configuration.
242 """ 275 """
243 # TODO: implement MigrateConfigDialog
244 from .MigrateConfigDialog import MigrateConfigDialog 276 from .MigrateConfigDialog import MigrateConfigDialog
245 277
246 config = self.__project.getData("migrate", "") 278 config = self.__project.getData("migrate", "")
247 dlg = MigrateConfigDialog(config) 279 dlg = MigrateConfigDialog(config)
248 if dlg.exec() == QDialog.Accepted: 280 if dlg.exec() == QDialog.Accepted:
375 self.__project, title=title, 407 self.__project, title=title,
376 msgSuccess=self.tr("\nMigration created successfully.") 408 msgSuccess=self.tr("\nMigration created successfully.")
377 ) 409 )
378 if dlg.startCommand("db", args): 410 if dlg.startCommand("db", args):
379 dlg.exec() 411 dlg.exec()
380 if dlg.normalExit(): 412 if dlg.normalExit():
381 versionsPattern = os.path.join( 413 versionsPattern = os.path.join(
382 self.__migrationsDirectory(abspath=True), 414 self.__migrationsDirectory(abspath=True),
383 "versions", "*.py") 415 "versions", "*.py")
384 for fileName in glob.iglob(versionsPattern): 416 for fileName in glob.iglob(versionsPattern):
385 self.__e5project.appendFile(fileName) 417 self.__e5project.appendFile(fileName)
386 418
387 ######################################################### 419 #########################################################
388 ## slots to up- and downgrade a databse 420 ## slots to up- and downgrade a databse
389 ######################################################### 421 #########################################################
422
423 @pyqtSlot()
424 def __upgradeDatabase(self):
425 """
426 Private slot to upgrade the database to the current migration.
427 """
428 title = self.tr("Upgrade Database")
429
430 self.__ensureMigrateConfigured()
431 migrations = self.__migrationsDirectory()
432
433 args = ["upgrade"]
434 if migrations:
435 args += ["--directory", migrations]
436
437 dlg = FlaskCommandDialog(
438 self.__project, title=title,
439 msgSuccess=self.tr("\nDatabase upgraded successfully.")
440 )
441 if dlg.startCommand("db", args):
442 dlg.exec()
443
444 @pyqtSlot()
445 def __downgradeDatabase(self):
446 """
447 Private slot to downgrade the database to the previous version.
448 """
449 title = self.tr("downgrade Database")
450
451 self.__ensureMigrateConfigured()
452 migrations = self.__migrationsDirectory()
453
454 args = ["downgrade"]
455 if migrations:
456 args += ["--directory", migrations]
457
458 dlg = FlaskCommandDialog(
459 self.__project, title=title,
460 msgSuccess=self.tr("\nDatabase downgraded successfully.")
461 )
462 if dlg.startCommand("db", args):
463 dlg.exec()

eric ide

mercurial