@Qc@sddlmZddlmZmZddlZddZdZdZeddd d d d Z da d e fdYZ e Z e jejdZe jejejejjdZe jejjejjejjdZe jejjejjejjejjdZe jejjejjejjejjdZe jejejjejjejjdZe jejjejjejjejjdZe jejj ejjejj!ejjdZ"e jejj#ejjejj$ejjdZ%e jejj&ejjejj'ejjdZ(e jej)ejj*fejjdZ+dS(i(t DefineModule(tfind_object_with_nametfind_object_with_old_nameNiiitnametDbGenericMigrationtauthors Oracle Corp.tversions1.0tGenericMigrationcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZRS(cCs.x'|jD]}|j|kr |jSq WdS(s\Finds the matching target object for a given source object, by searching in the migrationLogN(t migrationLogt logObjectt refObjecttNone(tselftstatet sourceObjecttlog((s&..\modules\db_generic_migration_grt.pytfindMatchingTargetObject!s cCs|jrx|jD]}|jj|jkr|jdkrk|jdkrk|j|jk rkqn|jdkr|jdkr|j|jk rqn|SqWndS(Ni(tgenericDatatypeMappingstsourceDatatypeNametuppertlengthConditionFromtlengthtlengthConditionToR (R R tcolumntdatatypettypemap((s&..\modules\db_generic_migration_grt.pytfindDatatypeMapping(s 11 cCs@d||jks8d||jj|jf|jkr<tStS(Ns%s:*s%s:%s.%s(t ignoreListtownerRtFalsetTrue(R R totypetobject((s&..\modules\db_generic_migration_grt.pyt shouldMigrate;s8cCs|}t|dkr}td7a|d tt}|r}tjj}d|_d||f|_|jj |q}n|S(Ni@ii>s5Identifier `%s` is too long and was truncated to `%s`( tlenttruncated_identifier_serialtstrtgrttclassest GrtLogEntryt entryTypeRtentriestappend(R RRt mysql_nametentry((s&..\modules\db_generic_migration_grt.pytmigrateIdentifier@s  c Cs1|j}td|jD}|j}| r`|jr`|jj}|jj|jjn|r|j}|}|j |||} | r|j | j j st jdd| j |f|jd||d| j |ftS|| j j |_| jdkr | j|_n| jdkr>| j|_n| jdkr\| j|_n| jdkrd|jkr|jjdqqnc|j |j r||j |_n8t jdd ||f|jd||d |tStS|jd||d |j|jj|jftStS( Ncss$|]}|jj|fVqdS(N(RR(t.0R((s&..\modules\db_generic_migration_grt.pys QstmigrateTableColumnsToMySQLs*Can't find mapped datatype %s for type %s isLUnknown mapped datatype "%s" for source type "%s" (check type mapping table)iitUNSIGNEDs#Can't find datatype %s for type %s sUnknown datatype "%s"s2Could not migrate type of column "%s" in "%s" (%s)(t targetCatalogtdicttsimpleDatatypest simpleTypetuserTypet actualTypetflagstextendRRthas_keyttargetDatatypeNameRR%t log_warningtaddMigrationLogEntryRRtscalet precisiont isUnsignedR*RRtformattedRawType( R R t source_columnt target_columnR1tmysql_simpleTypest source_typetsource_datatypettarget_datatypeR((s&..\modules\db_generic_migration_grt.pytmigrateDatatypeForColumnNsJ      cCs|S(N((R R t default_valueRARB((s&..\modules\db_generic_migration_grt.pytmigrateColumnDefaultValuescCs ||fS(N((R R tcharsett collationt source_objectt target_object((s&..\modules\db_generic_migration_grt.pytmigrateCharsetCollationsc Cstjj}|jd||d}|j|j||_|j|_|jjj }|j j |j ||_ |j r|j }tjj}||_ |j|j|j|jf\|_|_|_|_|j|_||_nHtjj}||_ d\|_|_|_|_d|_||_trtjddd}x|jD]} tjd|t|jdd|d t|jdtjd|t|jdd | j|j|| |} | r|jj| ntj|d 7}q\Wtjdd xw|jD]l} |j|| } xQ| jD]F} |j|d | soqNn|j|| } |j|| | qNWq,Wtjd dn|S(Nitis5.5.0gs Migrating...g?g|=isMigrating schema %s...s#Finalizing foreign key migration...ttablesg?sMigration finished(iiii( R%R&tdb_mysql_CatalogR<R-RtoldNamettargetConnectiontdriverRR3R8R1t targetVersiont GrtVersiont majorNumbert minorNumbert releaseNumbert buildNumberRRt send_progresstschematatbegin_progress_stepR"t migrateSchemaR*tend_progress_stepRRPR!tmigrateTableToMySQL2ndPass( R R tsource_catalogttarget_catalogRt targetRdbmstaTargetVersionRUtit sourceSchemat targetSchemat sourceTablet targetTable((s&..\modules\db_generic_migration_grt.pytmigrateCatalogsP     6     >, cCstjj}||_|jd||d}|j||j|j||\|_|_|j|j ||_ |j |_ |j |_ tj dd|j t rtjdd|j|||tjn|S(NiROg?s'Migrating schema contents for schema %sg?(R%R&tdb_mysql_SchemaRR<RNtdefaultCharacterSetNametdefaultCollationNameR-RRRtcommentR[RR]tmigrateSchemaContentsR_(R R RfR1RgR((s&..\modules\db_generic_migration_grt.pyR^s -   cCsGtg|jD]!}|j|d|r |^q tg|jD]!}|j|d|rA|^qAtg|jD]!}|j|d|rv|^qvd}d}x|jD]z} |j|d| r|j|| |} | r|jj| ntj||d|j | j f|d7}qqWx|jD]z} |j|d| r=|j || |} | r|jj| ntj||d|j | j f|d7}q=q=Wx|jD]z} |j|d| r|j || |}|r|jj|ntj||d |j | j f|d7}qqWdS( NRPtviewstroutinesg|=gsTable %s.%s migratedisView %s.%s migratedsRoutine %s.%s migrated( R"RPR!RpRqtmigrateTableToMySQLR*R%R[RtmigrateViewToMySQLtmigrateRoutineToMySQL(R R RgRfttabletviewtroutinettotalRet source_tablet target_tablet source_viewt target_viewtsource_routinettarget_routine((s&..\modules\db_generic_migration_grt.pyRos0$$$c Cstjj}|jd||d}||_|j|j||_|j|_|j|_|j |_ t rt }x[|j D]P}|j |||}|r|j j||jr|j|jqqqWt|dkr)|jdkr)x|j D]} d| _qW|j|_nx?|jD]4} |j|| |} | r3|jj| q3q3W|j||||jr t|jj dkr d} xPt|jj D]<\} } | jjr| dkr| } qd| j_qqW| dk r |jj j| dq n|jrHt d|jj D}ng}xR|j D]G} | jrX| j|krXd| _|jd||d| jqXqXWxZ|jD]L}|j|d|r|j|||}|r|jj|qqqWn|S(NiROicss|]}|jjVqdS(N(treferencedColumnR(R.R((s&..\modules\db_generic_migration_grt.pys 'ssdAutoincrement unset for column %s: Autoincrement for non primary key columns is not allowed in MySQLttriggers( R%R&tdb_mysql_TableR<RR-RRRRntisStubRtsettcolumnstmigrateTableColumnToMySQLR*t collationNametaddR"RmtpoptindicestmigrateTableIndexToMySQLtmigrateTablePrimaryKeyToMySQLt primaryKeyR t enumerateRt autoIncrementtreorderRR!tmigrateTriggerToMySQL(R R RhRgRiRtcolumn_collationst sourceColumnt targetColumnRt sourceIndext targetIndextfirst_autoinc_columntidxtpk_colst sourceTriggert targetTrigger((s&..\modules\db_generic_migration_grt.pyRrs^      ! !      cCsFx?|jD]4}|j|||}|r |jj|q q WdS(Ni(t foreignKeystmigrateTableForeignKeyToMySQLR*(R R RhRitsourceFKttargetFK((s&..\modules\db_generic_migration_grt.pyR`:s cCs|jr|jjdkr|jdkrxd|jjD]S}||krMPn|jr7|jjdkr7|jd||dd|_q7q7Wqn,tjd|j|jjj|jjfdS(Nt TIMESTAMPtCURRENT_TIMESTAMPismDEFAULT CURRENT_TIMESTAMP can only be used in the first TIMESTAMP column of the table. Default value removed.ROs6Could not migrate datatype of column %s in table %s.%s(R4Rt defaultValueRRR<R%t send_warning(R R RARBR((s&..\modules\db_generic_migration_grt.pyt"secondary_default_value_validationAs ! cCs|jj}tjj}||_|jd||d}|j|j||_|j|_x3|jD](}||jkrj|jj |qjqjW|j |_ |j |_ |j |_ |j |_ |j|_|j|_|j||j|j||\|_|_|j|_|j|||s/n|j||j|||_|jj|jj|jjfdkr|j|||n|S(NiROii(iii(RR%R&tdb_mysql_ColumnR<R-RRRR7R*tdefaultValueIsNullt isNotNullRR=R>tdatatypeExplicitParamsRNtcharacterSetNameRRnRGRIRRRWRXRYR(R R RARiRbRBRtflag((s&..\modules\db_generic_migration_grt.pyRRs.         - 'cCs+|jr't|j|jj|_ndS(Ni(RRRR(R R RhRi((s&..\modules\db_generic_migration_grt.pyRts c Cs|j}t|jdks3t|jdkrT|jd|dd|jdStjj}|jd||d}||_|j |j||_|j|_ |j |_ |j |_ |j |_ |j|_|j|_x|jD]}t|j|jj}|sA|jd||d|j|j|jfntjj} || _|| _|j| _|j| _|jr|jjjd kr|jdkrt|jtnt} | jdkrt| | j| _nr| jdkrC|jdkr| |jkr| | _qX|jjjd krX| | _qXnt| |j| _| j|jkr|jd ||d |j|j| jfqn|j| _|j| _|jj| qW|S( NiisrThe migration of table %s indices was attempted but either the source or the target table has no columns attributeROshThe column "%s" is part of source table "%s" index "%s" but there is not such column in the target tabletstringttexttblobis7Truncated key column length for column %s from %s to %s(sstringstextR(stextR(RR"RR<R RR%R&tdb_mysql_IndexR-RRt isPrimaryt deferabilitytuniquet indexTypeRnRRtdb_mysql_IndexColumnt columnLengthR4tgroupRtmint&MYSQL_MAX_INDEX_KEY_LENGTH_INNODB_UTF8tdescendR*( R R t source_indexRiRht target_indexRtsource_index_columntreferenced_index_colttarget_index_columntprefix_length_limit((s&..\modules\db_generic_migration_grt.pyR{sT *            ' #  c Cs|j}t|jdks3t|jdkrT|jd|dd|jdS|jdkrgdStjj }||_|jd||d}|j |j||_|j|_ |j j dd|_ |jj dd|_|j|_d|_|j|_|j|_|j|_|j|_y.|j||jj}|s]tdnWn@tk r}|jd||d t||jjf|SXy4|j||j} | std n| |_Wn=tk r}|jd||d t||jf|SXt} x|jD]} yT|j|| } | sntd |j | jd|jfn|jj| Wq%tk r}|jd||d t||jft} q%Xq%W| r|St} x|jD]} yW|j|| } | s.td |j | jd|jjfn|jj| Wqtk r}|jd||dt||jft} qXqW| r|S|jr|j||j|_n|S(NiiswThe migration of table %s foreign keys was attempted but either the source or the target table has no columns attributeiROt_t s=The referenced schema does not refer to a valid schema objects6"%s" while trying to get the schema for the table "%s"s;The referenced table does not refer to a valid table objectsF"%s" while trying to get the referenced table for the foreign key "%s"s+The column "%s" was not found in table "%s"sD"%s" while trying to get the target columns for the foreign key "%s"somigrateTableForeignKeysToMySQL: "%s" while trying to get the referenced target columns for the foreign key "%s"(RR"RR<R Rt modelOnlyR%R&tdb_mysql_ForeignKeyR-RRt deleteRuletreplacet updateRuleRt mandatorytreferencedMandatorytmanyRnRtreferencedTablet ValueErrort ExceptionR$RR*RtreferencedColumnstindex( R R t source_fkRiRht target_fkRtreferenced_schematerrtreferenced_tablet column_errorstsource_fk_columnt target_fk_col((s&..\modules\db_generic_migration_grt.pyRs *          (+ cCsddddddddd d d d d ddg}tjj}|jd||d||_x'|D]}t||t||qhWd|_|S(NRRRtdefinerteventt conditiontordert orientationttimingtreferenceNewTabletreferenceOldTabletreferenceNewRowtreferenceOldRowtsequenceNumbertenabledt sqlDefinitioniROi(R%R&tdb_mysql_TriggerR<Rtsetattrtgetattrt commentedOut(R R tsource_triggerRzt copy_membersttarget_triggertm((s&..\modules\db_generic_migration_grt.pyRs    cCszdddddg}tjj}||_|jd||dx'|D]}t||t||qJWd|_|S( NRRRtwithCheckConditiont isReadOnlyRiROi(R%R&t db_mysql_ViewRR<RRR(R R R{t target_schemaRR|R((s&..\modules\db_generic_migration_grt.pyRss     cCszdddddg}tjj}||_|jd||dx'|D]}t||t||qJWd|_|S( NRRRt routineTypeRRiROi(R%R&tdb_mysql_RoutineRR<RRR(R R R}RRR~R((s&..\modules\db_generic_migration_grt.pyRt$s     (t__name__t __module__RRR!R-RGRIRNRjR^RoRrR`RRRRRRRsRt(((s&..\modules\db_generic_migration_grt.pyRs(     5   8  ! F   "  ; R  cCsdS(NtGeneric((((s&..\modules\db_generic_migration_grt.pytgetTargetDBMSName4scCstj||S(N(tinstanceR-(RR((s&..\modules\db_generic_migration_grt.pyR-8scCstj||S(N(RRj(R Ra((s&..\modules\db_generic_migration_grt.pyRj=scCstj|||S(N(RR^(R RfR1((s&..\modules\db_generic_migration_grt.pyR^BscCstj|||S(N(RRr(R RhR((s&..\modules\db_generic_migration_grt.pyRrGscCstj|||S(N(RR`(R RhRi((s&..\modules\db_generic_migration_grt.pyR`LscCstj|||S(N(RR(R RRi((s&..\modules\db_generic_migration_grt.pyRQscCstj|||S(N(RR(R RRz((s&..\modules\db_generic_migration_grt.pyRVscCstj|||S(N(RRs(R R{R((s&..\modules\db_generic_migration_grt.pyRs[scCstj|||S(N(RRt(R R}R((s&..\modules\db_generic_migration_grt.pyRt`scCs"tjtjtjjj}|S(N(R%tListtOBJECTR&tdb_migration_MigrationParametert__grtclassname__(R tlist((s&..\modules\db_generic_migration_grt.pytgetMigrationOptionses(,twbRtworkbench.utilsRRR%Rt(MYSQL_MAX_INDEX_KEY_LENGTH_INNODB_LATIN1t%MYSQL_MAX_INDEX_KEY_LENGTH_NDBCLUSTERt ModuleInfoR#R RRtexporttSTRINGRR&t GrtLogObjectR-t db_Catalogtdb_migration_MigrationRjt db_SchemaR^tdb_TableRrtINTR`Rt db_ForeignKeyRRt db_TriggerRRtdb_ViewRsRt db_RoutineRttLISTRR(((s&..\modules\db_generic_migration_grt.pyts,   *09969999