479 """one or more applications.</p>""" |
479 """one or more applications.</p>""" |
480 )) |
480 )) |
481 self.databaseSqlResetSeqAct.triggered.connect( |
481 self.databaseSqlResetSeqAct.triggered.connect( |
482 self.__databaseSqlResetSequences) |
482 self.__databaseSqlResetSequences) |
483 self.actions.append(self.databaseSqlResetSeqAct) |
483 self.actions.append(self.databaseSqlResetSeqAct) |
|
484 |
|
485 self.databaseSqlMigrateAct = E5Action( |
|
486 self.tr('Apply Migration'), |
|
487 self.tr('&Apply Migration'), |
|
488 0, 0, |
|
489 self, 'django_database_sql_apply_migration') |
|
490 self.databaseSqlMigrateAct.setStatusTip(self.tr( |
|
491 'Prints the SQL statements to apply a migration of an' |
|
492 ' application')) |
|
493 self.databaseSqlMigrateAct.setWhatsThis(self.tr( |
|
494 """<b>Apply Migration</b>""" |
|
495 """<p>Prints the SQL statements to apply a migration of an""" |
|
496 """ application.</p>""" |
|
497 )) |
|
498 self.databaseSqlMigrateAct.triggered.connect( |
|
499 self.__databaseSqlMigrate) |
|
500 self.actions.append(self.databaseSqlMigrateAct) |
|
501 |
|
502 self.databaseSqlMigrateBackwardsAct = E5Action( |
|
503 self.tr('Unapply Migration'), |
|
504 self.tr('&Unapply Migration'), |
|
505 0, 0, |
|
506 self, 'django_database_sql_unapply_migration') |
|
507 self.databaseSqlMigrateBackwardsAct.setStatusTip(self.tr( |
|
508 'Prints the SQL statements to unapply a migration of an' |
|
509 ' application')) |
|
510 self.databaseSqlMigrateBackwardsAct.setWhatsThis(self.tr( |
|
511 """<b>Unapply Migration</b>""" |
|
512 """<p>Prints the SQL statements to unapply a migration of an""" |
|
513 """ application.</p>""" |
|
514 )) |
|
515 self.databaseSqlMigrateBackwardsAct.triggered.connect( |
|
516 lambda: self.__databaseSqlMigrate(backwards=True)) |
|
517 self.actions.append(self.databaseSqlMigrateBackwardsAct) |
484 |
518 |
485 def __initToolsActions(self): |
519 def __initToolsActions(self): |
486 """ |
520 """ |
487 Private method to define the tool actions. |
521 Private method to define the tool actions. |
488 """ |
522 """ |
744 """<p>This generates migrations for the Django project.</p>""" |
778 """<p>This generates migrations for the Django project.</p>""" |
745 )) |
779 )) |
746 self.makeMigrationsAct.triggered.connect(self.__makeMigrations) |
780 self.makeMigrationsAct.triggered.connect(self.__makeMigrations) |
747 self.actions.append(self.makeMigrationsAct) |
781 self.actions.append(self.makeMigrationsAct) |
748 |
782 |
749 # TODO: squashmigrations |
|
750 self.squashMigrationsAct = E5Action( |
783 self.squashMigrationsAct = E5Action( |
751 self.tr('Squash Migrations'), |
784 self.tr('Squash Migrations'), |
752 self.tr('S&quash Migrations'), |
785 self.tr('S&quash Migrations'), |
753 0, 0, |
786 0, 0, |
754 self, 'django_migration_squash') |
787 self, 'django_migration_squash') |
759 """<p>This squashes migrations of an application of the""" |
792 """<p>This squashes migrations of an application of the""" |
760 """ Django project.</p>""" |
793 """ Django project.</p>""" |
761 )) |
794 )) |
762 self.squashMigrationsAct.triggered.connect(self.__squashMigrations) |
795 self.squashMigrationsAct.triggered.connect(self.__squashMigrations) |
763 self.actions.append(self.squashMigrationsAct) |
796 self.actions.append(self.squashMigrationsAct) |
764 |
|
765 # TODO: sqlmigrate |
|
766 |
797 |
767 def initMenu(self): |
798 def initMenu(self): |
768 """ |
799 """ |
769 Public method to initialize the Django menu. |
800 Public method to initialize the Django menu. |
770 |
801 |
850 menu.addAction(self.databaseSqlDropTablesAct) |
881 menu.addAction(self.databaseSqlDropTablesAct) |
851 menu.addAction(self.databaseSqlDropIndexesAct) |
882 menu.addAction(self.databaseSqlDropIndexesAct) |
852 menu.addSeparator() |
883 menu.addSeparator() |
853 menu.addAction(self.databaseSqlFlushAct) |
884 menu.addAction(self.databaseSqlFlushAct) |
854 menu.addAction(self.databaseSqlResetSeqAct) |
885 menu.addAction(self.databaseSqlResetSeqAct) |
|
886 menu.addSeparator() |
|
887 menu.addAction(self.databaseSqlMigrateAct) |
|
888 menu.addAction(self.databaseSqlMigrateBackwardsAct) |
855 |
889 |
856 self.__menus["sql"] = menu |
890 self.__menus["sql"] = menu |
857 |
891 |
858 return menu |
892 return menu |
859 |
893 |
2145 Private slot to print the SQL statements for resetting sequences for |
2179 Private slot to print the SQL statements for resetting sequences for |
2146 one or more applications. |
2180 one or more applications. |
2147 """ |
2181 """ |
2148 self.__sqlCommand(self.tr("Reset Sequences"), "sqlsequencereset") |
2182 self.__sqlCommand(self.tr("Reset Sequences"), "sqlsequencereset") |
2149 |
2183 |
|
2184 def __databaseSqlMigrate(self, backwards=False): |
|
2185 """ |
|
2186 Private slot to print the SQL statements for a migration of an |
|
2187 application. |
|
2188 |
|
2189 @param backwards flag indicating to generate the SQL code to unapply |
|
2190 a migration |
|
2191 @type bool |
|
2192 """ |
|
2193 try: |
|
2194 path = self.__sitePath() |
|
2195 except DjangoNoSiteSelectedException: |
|
2196 return |
|
2197 |
|
2198 migrations = self.__getMigrations() |
|
2199 if not migrations: |
|
2200 E5MessageBox.information( |
|
2201 None, |
|
2202 self.tr("SQL Migrate"), |
|
2203 self.tr("""No migrations available.""")) |
|
2204 return |
|
2205 |
|
2206 title = self.tr("SQL Migrate") |
|
2207 |
|
2208 from .DjangoMigrationSelectionDialog import \ |
|
2209 DjangoMigrationSelectionDialog |
|
2210 dlg = DjangoMigrationSelectionDialog(migrations, |
|
2211 migrationRequired=True) |
|
2212 if dlg.exec_() == QDialog.Accepted: |
|
2213 app, migration = dlg.getData() |
|
2214 |
|
2215 args = [] |
|
2216 args.append(self.__getPythonExecutable()) |
|
2217 args.append("manage.py") |
|
2218 args.append("sqlmigrate") |
|
2219 if backwards: |
|
2220 args.append("--backwards") |
|
2221 args.append(app) |
|
2222 args.append(migration) |
|
2223 |
|
2224 fileFilter = self.tr("SQL Files (*.sql)") |
|
2225 |
|
2226 dia = DjangoDialog(title, fixed=True, linewrap=False, |
|
2227 saveFilters=fileFilter) |
|
2228 res = dia.startProcess(args, path, False) |
|
2229 if res: |
|
2230 dia.exec_() |
|
2231 |
2150 ################################################################## |
2232 ################################################################## |
2151 ## slots below implement migration related functions |
2233 ## slots below implement migration related functions |
2152 ################################################################## |
2234 ################################################################## |
2153 |
2235 |
2154 def __showMigrationsList(self): |
2236 def __showMigrationsList(self): |