Esempio n. 1
0
        public static void Extend(DatabaseDeclaration declaration, DwhBuilderConfiguration configuration)
        {
            if (configuration.UseEtlRunInfo)
            {
                var etlRunTable = new SqlTable(declaration.DefaultSchema, configuration.EtlRunTableName);
                declaration.AddTable(etlRunTable);

                etlRunTable.AddDateTime2("StartedOn", 7, false).SetPK();
                etlRunTable.AddNVarChar("Name", 200, false);
                etlRunTable.AddNVarChar("MachineName", 200, false);
                etlRunTable.AddNVarChar("UserName", 200, false);
                etlRunTable.AddDateTime2("FinishedOn", 7, true);
                etlRunTable.AddNVarChar("Result", 20, true);

                declaration.AddAutoNaming(new List <SqlTable> {
                    etlRunTable
                });

                foreach (var baseTable in declaration.GetTables())
                {
                    if (baseTable.HasProperty <EtlRunInfoDisabledProperty>() || baseTable == etlRunTable)
                    {
                        continue;
                    }

                    baseTable.AddDateTime2(configuration.EtlRunInsertColumnName, 7, false).SetForeignKeyToTable(etlRunTable.SchemaAndTableName);
                    baseTable.AddDateTime2(configuration.EtlRunUpdateColumnName, 7, false).SetForeignKeyToTable(etlRunTable.SchemaAndTableName);
                    baseTable.AddDateTime2(configuration.EtlRunFromColumnName, 7, false).SetForeignKeyToTable(etlRunTable.SchemaAndTableName);
                    baseTable.AddDateTime2(configuration.EtlRunToColumnName, 7, true).SetForeignKeyToTable(etlRunTable.SchemaAndTableName);
                }
            }

            var baseTablesWithHistory = declaration.GetTables()
                                        .Where(x => x.HasProperty <HasHistoryTableProperty>() &&
                                               x.SchemaAndTableName.TableName != configuration.EtlRunTableName)
                                        .ToList();

            var historyTables = new List <SqlTable>();

            foreach (var baseTable in baseTablesWithHistory)
            {
                var historyTable = CreateHistoryTable(baseTable, configuration);
                historyTables.Add(historyTable);
            }

            declaration.AddAutoNaming(historyTables);
        }