private void GetExtraTablesAndColumns( SourceCompatibilityReport report, StagingTablesBuilder latestSchema, IReadOnlyList <string> tablesInStage, IReadOnlyList <string> tablesInSource) { foreach (var srcTable in tablesInSource) { if (!tablesInStage.Contains(srcTable, StringComparer.OrdinalIgnoreCase)) { _log.DebugFormat("Extra table {0}", srcTable); report.AddExtraTable(srcTable); } else { // any extra columns in source? var srcSchema = GetSchemaForTable(srcTable); var columnsInSource = latestSchema.GetColumns(srcTable); foreach (var col in columnsInSource) { var srcCol = srcSchema.FirstOrDefault(x => x.Name.Equals(col.Name, StringComparison.OrdinalIgnoreCase)); if (srcCol == null) { _log.DebugFormat("Extra column {0}.{1}", srcTable, col.Name); report.AddExtraColumn(srcTable, col.Name); } } } } }
private void GetMissingTablesAndColumns( SourceCompatibilityReport report, StagingTablesBuilder latestSchema, IReadOnlyList <string> tablesInStage, IReadOnlyList <string> tablesInSource) { foreach (var stageTable in tablesInStage) { if (!stageTable.Equals(StagingTablesBuilder.PseudoRegisterMarkTable, StringComparison.OrdinalIgnoreCase)) { // this table is not actually a member of the CT7 schema if (!tablesInSource.Contains(stageTable, StringComparer.OrdinalIgnoreCase)) { _log.ErrorFormat("Missing table {0}", stageTable); report.AddMissingTable(stageTable); } else { // now check that the source columns exist... var srcSchema = GetSchemaForTable(stageTable); var columnsInStage = latestSchema.GetColumns(stageTable); foreach (var col in columnsInStage) { if (!col.Name.Equals(ColumnConstants.SrcTimetableIdColumnName, StringComparison.OrdinalIgnoreCase) && !col.Name.Equals(ColumnConstants.RegistersReqResolvedColumnName, StringComparison.OrdinalIgnoreCase)) { var srcCol = srcSchema.FirstOrDefault(x => x.Name.Equals(col.Name, StringComparison.OrdinalIgnoreCase)); if (srcCol == null) { _log.ErrorFormat("Missing column {0}.{1}", stageTable, col.Name); report.AddMissingColumn(stageTable, col.Name); } else if (!DbTypeMatching. MatchingDataTypes(srcCol.DataType, srcCol.CharacterMaxLength, col.SqlDbType, col.Length)) { _log.ErrorFormat("Incompatible data type for column {0}.{1}", stageTable, col.Name); report.BadDataType(stageTable, col.Name); } } } } } } }