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); }
private static void AddTable(TestDatabaseSimple dd) { var newTable = new SqlTable { SchemaAndTableName = "NewTableToMigrate" }; newTable.AddInt32("Id", false).SetPK().SetIdentity(); new PrimaryKeyNamingDefaultStrategy().SetPrimaryKeyName(newTable.Properties.OfType <PrimaryKey>().First()); newTable.AddNVarChar("Name", 100); dd.AddTable(newTable); }
#pragma warning disable IDE1006 // Naming Styles public void _010_GenerateScriptAndCreateTable(SqlEngineVersion version) #pragma warning restore IDE1006 // Naming Styles { _sqlExecuterTestAdapter.Check(version); _sqlExecuterTestAdapter.InitializeAndCreate(version.UniqueName); var dd = new DatabaseDefinition(null, new[] { MsSqlVersion.MsSql2016.GetTypeMapper(), OracleVersion.Oracle12c.GetTypeMapper(), SqLiteVersion.SqLite3.GetTypeMapper() }); var table = new SqlTable("HierarchyFromCsvToSqlTests"); var column = table.AddInt32("Id"); column.Properties.Add(new Identity(column) { Increment = 1, Seed = 1 }); table.AddNVarChar("Name", 100); dd.AddTable(table); var context = new Context { Settings = TestHelper.GetDefaultTestSettings(version), Logger = TestHelper.CreateLogger() }; var generator = SqlGeneratorFactory.CreateGenerator(version, context); var sql = generator.CreateTable(table); var result = _sqlExecuterTestAdapter.ExecuteNonQuery(version.UniqueName, sql); if (result != null) { Assert.Inconclusive(result); } }