private static void SetXref(SchemaManager manager, List <dynamic> foreignKeys, string leftTableName, string rightTableName) { string xrefTableName = string.Format("{0}{1}", leftTableName, rightTableName); string leftColumnName = string.Format("{0}Id", leftTableName); string rightColumnName = string.Format("{0}Id", rightTableName); manager.AddXref(leftTableName, rightTableName); manager.AddTable(xrefTableName); manager.AddColumn(xrefTableName, new Column("Id", DataTypes.Long, false)); manager.SetKeyColumn(xrefTableName, "Id"); manager.AddColumn(xrefTableName, new Column("Uuid", DataTypes.String, false)); manager.AddColumn(xrefTableName, new Column(leftColumnName, DataTypes.Long, false)); manager.AddColumn(xrefTableName, new Column(rightColumnName, DataTypes.Long, false)); AddForeignKey(foreignKeys, leftTableName, xrefTableName, leftColumnName); AddForeignKey(foreignKeys, rightTableName, xrefTableName, rightColumnName); }
public virtual SchemaDefinition Extract(SchemaManager schemaManager) { SchemaDefinition result = new SchemaDefinition { Name = GetSchemaName() }; schemaManager.CurrentSchema = result; // GetTableNames GetTableNames().Each(tableName => { FireEvent(ProcessingTable, new SchemaExtractorEventArgs { Table = tableName }); FireEvent(ClassNameFormatting, new SchemaExtractorEventArgs { Table = tableName }); string className = GetClassName(tableName); NameMap.Set(new TableNameToClassName { TableName = tableName, ClassName = className }); FireEvent(ClassNameFormatted, new SchemaExtractorEventArgs { Table = tableName }); schemaManager.AddTable(tableName, className);// add each table // GetColumnNames GetColumnNames(tableName).Each(columnName => { FireEvent(ProcessingColumn, new SchemaExtractorEventArgs { Column = columnName }); // add each column; schemaManager.AddColumn(tableName, CreateColumn(tableName, columnName)); FireEvent(ProcessingColumnComplete, new SchemaExtractorEventArgs { Column = columnName }); }); string keyColumnName = GetKeyColumnName(tableName); if (!string.IsNullOrEmpty(keyColumnName)) { schemaManager.SetKeyColumn(tableName, keyColumnName); } FireEvent(ProcessingTableComplete, new SchemaExtractorEventArgs { Table = tableName }); }); // GetForeignKeyColumns GetForeignKeyColumns().Each(fk => { FireEvent(ProcessingForeignKey, new SchemaExtractorEventArgs { ForeignKeyColumn = fk }); // set each foreignkey schemaManager.SetForeignKey(fk.ReferencedTable, fk.TableName, fk.Name, GetKeyColumnName(fk.ReferencedTable), NameFormatter); FireEvent(ProcessingForeignComplete, new SchemaExtractorEventArgs { ForeignKeyColumn = fk }); }); SaveNameMap(schemaManager); SetClassNamesOnColumns(schemaManager); return(result); }