public LoadDiagramColumnNode(LoadDiagramTableNode tableNode, IHasStageSpecificRuntimeName column, LoadBubble bubble) { _tableNode = tableNode; _column = column; _bubble = bubble; ColumnName = _column.GetRuntimeName(_bubble.ToLoadStage()); var colInfo = _column as ColumnInfo; var preLoadDiscarded = _column as PreLoadDiscardedColumn; if (preLoadDiscarded != null) { _expectedDataType = preLoadDiscarded.SqlDataType; } else if (colInfo != null) { _expectedDataType = colInfo.GetRuntimeDataType(_bubble.ToLoadStage()); } else { throw new Exception("Expected _column to be ColumnInfo or PreLoadDiscardedColumn but it was:" + _column.GetType().Name); } }
public LoadDiagramTableNode(LoadDiagramDatabaseNode databaseNode, TableInfo tableInfo, LoadBubble bubble, HICDatabaseConfiguration config) { _databaseNode = databaseNode; TableInfo = tableInfo; Bubble = bubble; _config = config; State = LoadDiagramState.Anticipated; TableName = TableInfo.GetRuntimeName(Bubble); //only reference schema if it is LIVE string schema = bubble >= LoadBubble.Live ? tableInfo.Schema: null; Table = databaseNode.Database.ExpectTable(TableName, schema); var cols = TableInfo.GetColumnsAtStage(Bubble.ToLoadStage()) .Select(c => new LoadDiagramColumnNode(this, c, Bubble)); _anticipatedChildren.AddRange(cols); }
public void CloneTable(DiscoveredDatabase srcDatabaseInfo, DiscoveredDatabase destDatabaseInfo, DiscoveredTable sourceTable, string destTableName, bool dropHICColumns, bool dropIdentityColumns, bool allowNulls, PreLoadDiscardedColumn[] dilutionColumns) { if (!sourceTable.Exists()) { throw new Exception("Table " + sourceTable + " does not exist on " + srcDatabaseInfo); } //new table will start with the same name as the as the old scripted one DiscoveredTable newTable = destDatabaseInfo.ExpectTable(destTableName); var sql = sourceTable.ScriptTableCreation(allowNulls, allowNulls, false /*False because we want to drop these columns entirely not just flip to int*/, newTable); _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "Creating table with SQL:" + sql)); using (var con = destDatabaseInfo.Server.GetConnection()) { con.Open(); using (var cmd = destDatabaseInfo.Server.GetCommand(sql, con)) cmd.ExecuteNonQuery(); } if (!newTable.Exists()) { throw new Exception("Table '" + newTable + "' not found in " + destDatabaseInfo + " despite running table creation SQL!"); } foreach (DiscoveredColumn column in newTable.DiscoverColumns()) { bool drop = false; var colName = column.GetRuntimeName(); if (column.IsAutoIncrement) { drop = true; } //drop hic_ columns if (SpecialFieldNames.IsHicPrefixed(colName) && dropHICColumns) { drop = true; } //if the ColumnInfo is explicitly marked to be ignored if (_tableInfo.ColumnInfos.Any(c => c.IgnoreInLoads && c.GetRuntimeName(_copyToBubble.ToLoadStage()).Equals(colName))) { _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"{colName} will be dropped because it is marked IgnoreInLoads")); drop = true; } //also drop any columns we have specifically been told to ignore in the DLE configuration if (_hicDatabaseConfiguration.IgnoreColumns != null && _hicDatabaseConfiguration.IgnoreColumns.IsMatch(colName)) { _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"{colName} will be dropped because it is matches the gloabl ignores pattern ({_hicDatabaseConfiguration.IgnoreColumns})")); drop = true; } //drop the data load run ID field and validFrom fields, we don't need them in STAGING or RAW, it will be hard coded in the MERGE migration with a fixed value anyway. if (colName.Equals(SpecialFieldNames.DataLoadRunID) || colName.Equals(SpecialFieldNames.ValidFrom)) { drop = true; } var dilution = dilutionColumns.SingleOrDefault(c => c.GetRuntimeName().Equals(colName)); if (dilution != null) { _listener.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, $"Altering diluted column {colName} to {dilution.Data_type}")); column.DataType.AlterTypeTo(dilution.Data_type); } if (drop) { newTable.DropColumn(column); } } }