public virtual SchemaDefinition Extract() { SchemaManager schemaManager = new SchemaManager(); schemaManager.AutoSave = false; schemaManager.SchemaTempPathProvider = SchemaTempPathProvider; SchemaDefinition result = Extract(schemaManager); return(result); }
public override void Execute(string tableName, SchemaManager manager) { manager.AddColumn(tableName, new Column("Created", DataTypes.DateTime, false)); manager.AddColumn(tableName, new Column("Modified", DataTypes.DateTime, false)); if (IncludeModifiedBy) { manager.AddColumn(tableName, new Column("ModifiedBy", DataTypes.String, false)); } if (IncludeCreatedBy) { manager.AddColumn(tableName, new Column("CreatedBy", DataTypes.String, false)); } }
public static SchemaDefinition MapSchemaClassAndPropertyNames(SchemaNameMap nameMap, SchemaDefinition schema) { SchemaManager mgr = new SchemaManager(schema); mgr.AutoSave = false; Parallel.ForEach(nameMap.TableNamesToClassNames, (map) => { mgr.SetTableClassName(map.TableName, map.ClassName); }); Parallel.ForEach(schema.Tables, (table) => { Parallel.ForEach(table.Columns, column => mgr.SetColumnPropertyName(table.Name, column.Name, nameMap.GetPropertyName(table.Name, column.Name))); }); return(mgr.CurrentSchema); }
protected static void ProcessXrefs(SchemaManager manager, dynamic rehydrated, List <dynamic> foreignKeys) { if (rehydrated["xrefs"] != null) { foreach (dynamic xref in rehydrated["xrefs"]) { string leftTableName = (string)xref[0]; string rightTableName = (string)xref[1]; Args.ThrowIfNullOrEmpty(leftTableName, "xref[0]"); Args.ThrowIfNullOrEmpty(rightTableName, "xref[1]"); SetXref(manager, foreignKeys, leftTableName, rightTableName); } } }
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); }
private static void AddColumns(SchemaManager manager, dynamic table, string tableName) { if (table["cols"] != null) { foreach (dynamic column in table["cols"]) { PropertyDescriptorCollection columnProperties = TypeDescriptor.GetProperties(column); bool allowNull = column["Null"] == null ? true : (bool)column["Null"]; string maxLength = column["MaxLength"] == null ? "" : (string)column["MaxLength"]; foreach (PropertyDescriptor pd in columnProperties) { if (!pd.Name.Equals("Null") && !pd.Name.Equals("MaxLength")) { DataTypes type = (DataTypes)Enum.Parse(typeof(DataTypes), (string)pd.GetValue(column)); string name = pd.Name; manager.AddColumn(tableName, new Column(name, type, allowNull, maxLength)); } } } } }
protected virtual void SaveNameMap(SchemaManager schemaManager) { NameMap.Save(Path.Combine(RuntimeSettings.AppDataFolder, "{0}_NameMap.json"._Format(schemaManager.CurrentSchema.Name))); }
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); }
public override void Execute(string tableName, SchemaManager manager) { manager.AddColumn(tableName, new Column(ColumnName, DataType, AllowNull)); }
public abstract void Execute(string tableName, SchemaManager manager);
public override void Execute(string tableName, SchemaManager manager) { base.Execute(tableName, manager); manager.SetKeyColumn(tableName, ColumnName); }