예제 #1
0
 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));
     }
 }
예제 #2
0
        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);
        }
예제 #3
0
 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));
                 }
             }
         }
     }
 }
예제 #4
0
        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);
        }
예제 #5
0
 public override void Execute(string tableName, SchemaManager manager)
 {
     manager.AddColumn(tableName, new Column(ColumnName, DataType, AllowNull));
 }