1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
|
# Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
import mforms
import grt
from workbench.ui import WizardPage
from workbench.template import MiniTemplate
text_template = """
------------------------------------------------------------------------------------
MySQL Workbench Migration Wizard Report
Date: {{date}}
Source: {{sourceRdbmsName}} {{sourceRdbmsVersion}}
Target: {{targetRdbmsName}} {{targetRdbmsVersion}}
------------------------------------------------------------------------------------
I. Migration
1. Summary
Number of migrated schemas: {{#catalog.schemata}}
[[catalog.schemata]]
{{:#}}. {{name}}
Source Schema: {{sourceName}}
- Tables: {{#tables}}
- Triggers: {{#triggers}}
- Views: {{#views}}
- Stored Procedures: {{#procedures}}
- Functions: {{#functions}}
[[/catalog.schemata]]
2. Migration Issues
[[migrationLog]] - {{refObject.name}}
[[entries]][[?name]]{{entryType}} {{name}}[[/name]][[/entries]]
[[/migrationLog]]
3. Object Creation Issues
[[creationLog]] - {{refObject.name}}
[[entries]][[?name]]{{entryType}} {{name}}[[/name]][[/entries]]
[[/creationLog]]
4. Migration Details
[[catalog.schemata]]\
[[tables]]
4.{{:#}}. [[?name]]Table {{owner.name}}.{{name}} ({{sourceName}})
[[?comment]]{{comment}}[[/comment]]
Columns:
[[columns]]\
[[?name]] - {{name}} {{formattedRawType}} {{flags}} {{defaultValue}} [[?comment]]#{{comment}}[[/comment]]
[[!name]]column not migrated
[[/name]]\
[[/columns]]
Foreign Keys:
[[foreignKeys]]\
- {{name}} ([[columns]]{{name}}[[/columns]]) ON {{referencedTable.name}} ([[referencedColumns]]{{name}}[[/referencedColumns]])
[[/foreignKeys]]
Indices:
[[indices]]\
- {{name}} ([[columns]]{{referencedColumn.name}}[[?if|columnLength > 0]]({{columnLength}})[[/if]][[?needsep]], [[/needsep]][[/columns]])
[[/indices]]\
[[!name]]\
4.{{:#}} Table {{sourceName}} was not migrated
[[/name]]
[[/tables]]\
[[/catalog.schemata]]\
II. Data Copy
[[dataTransferLog]] - {{logObject.name}}
[[entries]]\
[[?name]]{{entryType}} {{name}}[[/name]]\
[[/entries]]
[[/dataTransferLog]]
"""
class FinalReportView(WizardPage):
def __init__(self, main):
WizardPage.__init__(self, main, "Migration Report")
self.main.add_wizard_page(self, "Report", "Migration Report")
self._report = mforms.newTextBox(mforms.VerticalScrollBar)
self.content.add(self._report, True, True)
self.next_button.set_text("Finish")
def page_activated(self, advancing):
if advancing:
self.generate_migration_report()
if "GenerateBulkCopyScript" in self.main.plan.state.dataBulkTransferParams.keys():
self.advanced_button.set_text("Open folder that contains generated script")
self.advanced_button.show(True)
else:
self.advanced_button.show(False)
WizardPage.page_activated(self, advancing)
def generate_report_data(self):
state = self.main.plan.state
source_catalog = state.sourceCatalog
target_catalog = state.targetCatalog
def find_migrated_object(object, state):
for log in state.migrationLog:
if log.logObject == object:
return log.refObject
return None
def reportize_object(object, state):
logEntries = []
for log in state.migrationLog:
if log.logObject == object:
logEntries = log.entries
break
createEntries = []
for log in state.creationLog:
if log.logObject == object:
createEntries = log.entries
break
o = {
"migrationMessages" : [ {"type" : ["note", "warning", "error"][max(min(e.entryType, 2), 0)], "message" : e.name } for e in logEntries],
"createMessages" : [ {"type" : ["note", "warning", "error"][max(min(e.entryType, 2), 0)], "message" : e.name } for e in createEntries]
}
if object:
for member in object.__grtmembers__:
v = getattr(object, member)
if type(v) in (int, float, str, unicode):
o[member] = v
elif type(v) is grt.List:
if v.__contenttype__[0] in (grt.STRING, grt.INT):
o[member] = ", ".join(v)
else:
o[member] = [reportize_object(x, state) for x in v]
elif isinstance(v, grt.Object):
o[member] = v
else:
o[member] = v
return o
def reportize_table(table, state):
migrated = find_migrated_object(table, state)
obj = reportize_object(migrated, state)
obj.update({
"sourceName" : table.name,
"columns" : [reportize_object(column, state) for column in migrated.columns] if migrated else [],
"foreignKeys" : [reportize_object(fk, state) for fk in migrated.foreignKeys] if migrated else [],
"indices" : [reportize_object(index, state) for index in migrated.indices] if migrated else [],
})
return obj
def reportize_schema(schema, state):
tschema = find_migrated_object(schema, state)
schema_data = reportize_object(tschema, state)
schema_data.update({
"sourceName" : schema.name,
"tables" : [reportize_table(table, state) for table in schema.tables],
"triggers" : [reportize_object(trigger, state) for table in schema.tables for trigger in table.triggers],
"views" : [reportize_object(view, state) for view in schema.views],
"functions" : [reportize_object(func, state) for func in schema.routines if func.routineType == "FUNCTION"],
"procedures" : [reportize_object(sp, state) for sp in schema.routines if sp.routineType == "PROCEDURE"],
})
return schema_data
def reportize_log(log):
return {
"logObject" : {"name" : log.logObject.name },
"refObject" : {"name" : log.refObject.name if log.refObject else "" },
"entries" : [ {"entryType" : ["note", "warning", "error"][max(min(e.entryType, 2), 0)], "name" : e.name } for e in log.entries]
}
def reportize_transfer_log(log):
return {
"logObject" : {"name" : log.name },
"entries" : [ {"entryType" : ["", "warning", "error"][max(min(e.entryType, 2), 0)], "name" : e.name } for e in log.entries]
}
import time
report_data = {
"date" : time.ctime(),
"sourceRdbmsName" : state.sourceConnection.driver.owner.caption,
"sourceRdbmsVersion" : "%s.%s.%s" % (state.sourceDBVersion.majorNumber, state.sourceDBVersion.minorNumber, state.sourceDBVersion.releaseNumber),
"targetRdbmsName" : state.targetConnection.driver.owner.caption,
"targetRdbmsVersion" : "%s.%s.%s" % (state.targetDBVersion.majorNumber, state.targetDBVersion.minorNumber, state.targetDBVersion.releaseNumber),
"sourceServer" : state.sourceConnection.hostIdentifier,
"targetServer" : state.targetConnection.hostIdentifier,
"creationLog" : [reportize_log(o) for o in state.creationLog if len(o.entries) > 1],
"migrationLog" : [reportize_log(o) for o in state.migrationLog if len(o.entries) > 1],
"dataTransferLog" : [reportize_transfer_log(o) for o in state.dataTransferLog if len(o.entries) > 0],
"catalog" : {
"sourceName" : source_catalog.name,
"name" : target_catalog.name,
"schemata" : [reportize_schema(schema, state) for schema in source_catalog.schemata],
}
}
return report_data
def go_next(self):
self.main.close()
def generate_migration_report(self):
report_data = self.generate_report_data()
try:
report = MiniTemplate(text_template).render(report_data)
except Exception, exc:
report = "Error generating report: %s" % exc
self._report.set_value(report)
def go_advanced(self):
mforms.Utilities.reveal_file(self.main.plan.state.dataBulkTransferParams["GenerateBulkCopyScript"])
|