154 self.upgradeDatabaseAct.setWhatsThis(self.tr( |
155 self.upgradeDatabaseAct.setWhatsThis(self.tr( |
155 """<b>Upgrade Database</b>""" |
156 """<b>Upgrade Database</b>""" |
156 """<p>Upgrades the database to the current migration.</p>""" |
157 """<p>Upgrades the database to the current migration.</p>""" |
157 )) |
158 )) |
158 self.upgradeDatabaseAct.triggered.connect( |
159 self.upgradeDatabaseAct.triggered.connect( |
159 self.__upgradeDatabase) |
160 self.upgradeDatabase) |
160 self.actions.append(self.upgradeDatabaseAct) |
161 self.actions.append(self.upgradeDatabaseAct) |
161 |
162 |
162 # TODO: add action for flask db downgrade |
|
163 self.downgradeDatabaseAct = E5Action( |
163 self.downgradeDatabaseAct = E5Action( |
164 self.tr('Downgrade Database'), |
164 self.tr('Downgrade Database'), |
165 self.tr('&Downgrade Database'), |
165 self.tr('&Downgrade Database'), |
166 0, 0, |
166 0, 0, |
167 self, 'flask_downgrade_database') |
167 self, 'flask_downgrade_database') |
170 self.downgradeDatabaseAct.setWhatsThis(self.tr( |
170 self.downgradeDatabaseAct.setWhatsThis(self.tr( |
171 """<b>Downgrade Database</b>""" |
171 """<b>Downgrade Database</b>""" |
172 """<p>Downgrades the database to the previous version.</p>""" |
172 """<p>Downgrades the database to the previous version.</p>""" |
173 )) |
173 )) |
174 self.downgradeDatabaseAct.triggered.connect( |
174 self.downgradeDatabaseAct.triggered.connect( |
175 self.__downgradeDatabase) |
175 self.downgradeDatabase) |
176 self.actions.append(self.downgradeDatabaseAct) |
176 self.actions.append(self.downgradeDatabaseAct) |
|
177 |
|
178 ######################################################### |
|
179 ## actions to show migrations history information |
|
180 ######################################################### |
|
181 |
|
182 self.migrationSummaryAct = E5Action( |
|
183 self.tr('Show Migrations Summary'), |
|
184 self.tr('Show Migrations &Summary'), |
|
185 0, 0, |
|
186 self, 'flask_show_migrations_summary') |
|
187 self.migrationSummaryAct.setStatusTip(self.tr( |
|
188 'Show a summary of the created database migrations')) |
|
189 self.migrationSummaryAct.setWhatsThis(self.tr( |
|
190 """<b>Show Migrations Summary</b>""" |
|
191 """<p>Shows a summary list of the created database""" |
|
192 """ migrations.</p>""" |
|
193 )) |
|
194 self.migrationSummaryAct.triggered.connect( |
|
195 self.__showMigrationsSummary) |
|
196 self.actions.append(self.migrationSummaryAct) |
|
197 |
|
198 self.migrationHistoryAct = E5Action( |
|
199 self.tr('Show Migrations History'), |
|
200 self.tr('Show Migrations &History'), |
|
201 0, 0, |
|
202 self, 'flask_show_migrations_history') |
|
203 self.migrationHistoryAct.setStatusTip(self.tr( |
|
204 'Show the full history of the created database migrations')) |
|
205 self.migrationHistoryAct.setWhatsThis(self.tr( |
|
206 """<b>Show Migrations History</b>""" |
|
207 """<p>Shows the full history of the created database""" |
|
208 """ migrations.</p>""" |
|
209 )) |
|
210 self.migrationHistoryAct.triggered.connect( |
|
211 self.__showMigrationsHistory) |
|
212 self.actions.append(self.migrationHistoryAct) |
177 |
213 |
178 def initMenu(self): |
214 def initMenu(self): |
179 """ |
215 """ |
180 Public method to initialize the flask-migrate menu. |
216 Public method to initialize the flask-migrate menu. |
181 |
217 |
419 ######################################################### |
466 ######################################################### |
420 ## slots to up- and downgrade a databse |
467 ## slots to up- and downgrade a databse |
421 ######################################################### |
468 ######################################################### |
422 |
469 |
423 @pyqtSlot() |
470 @pyqtSlot() |
424 def __upgradeDatabase(self): |
471 def upgradeDatabase(self, revision=None): |
425 """ |
472 """ |
426 Private slot to upgrade the database to the current migration. |
473 Public slot to upgrade the database to the current migration. |
|
474 |
|
475 @param revision migration revision to upgrade to |
|
476 @type str |
427 """ |
477 """ |
428 title = self.tr("Upgrade Database") |
478 title = self.tr("Upgrade Database") |
429 |
479 |
430 self.__ensureMigrateConfigured() |
480 self.__ensureMigrateConfigured() |
431 migrations = self.__migrationsDirectory() |
481 migrations = self.__migrationsDirectory() |
432 |
482 |
433 args = ["upgrade"] |
483 args = ["upgrade"] |
434 if migrations: |
484 if migrations: |
435 args += ["--directory", migrations] |
485 args += ["--directory", migrations] |
|
486 if revision: |
|
487 args.append(revision) |
436 |
488 |
437 dlg = FlaskCommandDialog( |
489 dlg = FlaskCommandDialog( |
438 self.__project, title=title, |
490 self.__project, title=title, |
439 msgSuccess=self.tr("\nDatabase upgraded successfully.") |
491 msgSuccess=self.tr("\nDatabase upgraded successfully.") |
440 ) |
492 ) |
441 if dlg.startCommand("db", args): |
493 if dlg.startCommand("db", args): |
442 dlg.exec() |
494 dlg.exec() |
443 |
495 |
444 @pyqtSlot() |
496 @pyqtSlot() |
445 def __downgradeDatabase(self): |
497 def downgradeDatabase(self, revision=None): |
446 """ |
498 """ |
447 Private slot to downgrade the database to the previous version. |
499 Public slot to downgrade the database to the previous version. |
448 """ |
500 |
449 title = self.tr("downgrade Database") |
501 @param revision migration revision to downgrade to |
|
502 @type str |
|
503 """ |
|
504 title = self.tr("Downgrade Database") |
450 |
505 |
451 self.__ensureMigrateConfigured() |
506 self.__ensureMigrateConfigured() |
452 migrations = self.__migrationsDirectory() |
507 migrations = self.__migrationsDirectory() |
453 |
508 |
454 args = ["downgrade"] |
509 args = ["downgrade"] |
455 if migrations: |
510 if migrations: |
456 args += ["--directory", migrations] |
511 args += ["--directory", migrations] |
|
512 if revision: |
|
513 args.append(revision) |
457 |
514 |
458 dlg = FlaskCommandDialog( |
515 dlg = FlaskCommandDialog( |
459 self.__project, title=title, |
516 self.__project, title=title, |
460 msgSuccess=self.tr("\nDatabase downgraded successfully.") |
517 msgSuccess=self.tr("\nDatabase downgraded successfully.") |
461 ) |
518 ) |
462 if dlg.startCommand("db", args): |
519 if dlg.startCommand("db", args): |
463 dlg.exec() |
520 dlg.exec() |
|
521 |
|
522 ######################################################### |
|
523 ## slots to show migrations history information |
|
524 ######################################################### |
|
525 |
|
526 @pyqtSlot() |
|
527 def __showMigrationsSummary(self): |
|
528 """ |
|
529 Private slot to show a migrations history summary. |
|
530 """ |
|
531 from .MigrateSummaryDialog import MigrateSummaryDialog |
|
532 |
|
533 self.__ensureMigrateConfigured() |
|
534 migrations = self.__migrationsDirectory() |
|
535 |
|
536 if self.__migrationSummaryDialog is None: |
|
537 self.__migrationSummaryDialog = MigrateSummaryDialog( |
|
538 self.__project, self, migrations=migrations) |
|
539 |
|
540 self.__migrationSummaryDialog.showSummary() |
|
541 |
|
542 @pyqtSlot() |
|
543 def __showMigrationsHistory(self): |
|
544 """ |
|
545 Private slot to show the full migrations history. |
|
546 """ |
|
547 title = self.tr("Migrations History") |
|
548 |
|
549 self.__ensureMigrateConfigured() |
|
550 migrations = self.__migrationsDirectory() |
|
551 |
|
552 args = ["history", "--indicate-current", "--verbose"] |
|
553 if migrations: |
|
554 args += ["--directory", migrations] |
|
555 |
|
556 dlg = FlaskCommandDialog(self.__project, title=title) |
|
557 if dlg.startCommand("db", args): |
|
558 dlg.exec() |