public void Bim( [Option(LongName = "connectionString", ShortName = "c")] string connectionString, [Option(LongName = "sqlType", ShortName = "t")] string sqlType, [Option(LongName = "databaseName", ShortName = "b")] string databaseName, [Option(LongName = "patternFileName", ShortName = "p")] string patternFileName) { var version = SqlEngineVersions.GetVersion(sqlType); var connString = new NamedConnectionString( version.GetType().Name, version.ProviderName, connectionString, version.VersionString); var context = CreateContext(version); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(connString, context, null); var dd = ddlReader.GetDatabaseDefinition(); var documenterContext = CreateDocumenterContext(context, patternFileName); var generator = new BimGenerator(documenterContext, version, databaseName); generator.Generate(dd); }
public void ReadTables(SqlEngineVersion version) { Init(version, null); TestHelper.CheckFeature(version, "ReadDdl"); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(_sqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], _sqlExecuterTestAdapter.GetContext(version), new ForeignKeyToAnotherSchema().GetSchemaNames().ToList()); var db = ddlReader.GetDatabaseDefinition(); var parent = db.GetTable("Parent", "Parent"); var pkParent = parent.Properties.OfType <PrimaryKey>().FirstOrDefault(); Assert.IsNotNull(pkParent); Assert.AreEqual(1, pkParent.SqlColumns.Count); Assert.AreEqual("Id", pkParent.SqlColumns[0].SqlColumn.Name); var child = db.GetTable("Child", "Child"); var fks = child.Properties.OfType <ForeignKey>().ToList(); Assert.AreEqual(1, fks.Count); var fk1 = fks[0]; Assert.AreEqual(1, fk1.ForeignKeyColumns.Count); Assert.AreEqual(child.Columns["Parent.ParentId"], fk1.ForeignKeyColumns[0].ForeignKeyColumn); Assert.AreEqual(parent.Columns["Id"], fk1.ForeignKeyColumns[0].ReferredColumn); Assert.AreEqual(parent.SchemaAndTableName, fk1.ReferredTable.SchemaAndTableName); }
public void FkCheckNoCheckTest() { var version = MsSqlVersion.MsSql2016; var dd = new TestDatabaseFk(); dd.SetVersions(version.GetTypeMapper()); Init(version, dd); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader( SqlExecuterTestAdapter.ConnectionStrings[version.UniqueName] , SqlExecuterTestAdapter.GetContext(version), dd.GetSchemaNames().ToList()); var ddInDatabase = ddlReader.GetDatabaseDefinition(); var fk = dd.GetTable("Foreign").Properties.OfType <ForeignKey>().First(); Assert.AreEqual("true", fk.SqlEngineVersionSpecificProperties[version, "Nocheck"]); fk.SqlEngineVersionSpecificProperties[version, "Nocheck"] = "false"; var comparer = new Comparer(SqlExecuterTestAdapter.GetContext(version)); var changes = comparer.Compare(ddInDatabase, dd); _ = changes[0] as ForeignKeyChange; _ = new DatabaseMigrator(SqlExecuterTestAdapter.GetExecuter(version.UniqueName), SqlGeneratorFactory.CreateMigrationGenerator(version, SqlExecuterTestAdapter.GetContext(version))); // TODO change FK // databaseMigrator. }
public void ReadTables(SqlEngineVersion version) { Init(version, null); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader( _sqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], _sqlExecuterTestAdapter.GetContext(version), null); _ = ddlReader.GetDatabaseDefinition(); }
//[SqlVersions(typeof(MsSql2016))] //public void ReadTables(SqlVersion version) public void ReadTables() { var version = MsSqlVersion.MsSql2016; Init(version, null); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader( _sqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], _sqlExecuterTestAdapter.GetContext(version), null); var dd = ddlReader.GetDatabaseDefinition(); var _ = dd.GetTable("Company").Properties.OfType <UniqueConstraint>().First(); }
public void ReadTables(SqlEngineVersion version) { TestHelper.CheckFeature(version, "ReadDdl"); Init(version, null); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader( _sqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], _sqlExecuterTestAdapter.GetContext(version), null); var dd = ddlReader.GetDatabaseDefinition(); var _ = dd.GetTable("Company").Properties.OfType <Index>().First(); }
public void Generate( [Option(LongName = "connectionString", ShortName = "c", Description = "Provide a valid connection string to the database")] string connectionString, [Option(LongName = "singleOrMulti", ShortName = "m", Description = "multi for multi file, single for single file generation")] string singleOrMulti, [Option(LongName = "sqlType", ShortName = "t")] string sqlType, [Option(LongName = "namespace", ShortName = "n")] string @namespace, [Option(LongName = "newDatabaseName", ShortName = "b")] string newDatabaseName, [Option(LongName = "patternFileName", ShortName = "p")] string patternFileName, [Option(LongName = "flags", ShortName = "f")] List <string> flags) { var version = SqlEngineVersions.GetVersion(sqlType); var connString = new NamedConnectionString( version.GetType().Name, version.ProviderName, connectionString, version.VersionString); var context = CreateContext(version); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(connString, context, null); var dd = ddlReader.GetDatabaseDefinition(); var generatorContext = CreateGeneratorContext(context, patternFileName); if (flags != null) { SetSettingsFromFlags(flags, generatorContext.GeneratorSettings); } var writer = CSharpWriterFactory.GetCSharpWriter(version, generatorContext, newDatabaseName); var generator = new CSharpGenerator(writer, version, newDatabaseName, @namespace); if (singleOrMulti == "s" || singleOrMulti == "single") { generator.GenerateSingleFile(dd, newDatabaseName + ".cs"); } else { generator.GenerateMultiFile(dd); } }
private static DatabaseMigrator ProcessAndGetMigrator(SqlEngineVersion version, DatabaseDefinitions dds, out List <IMigration> changes) { Init(version, dds.Original); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(SqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], SqlExecuterTestAdapter.GetContext(version), dds.Original.GetSchemaNames().ToList()); var ddInDatabase = ddlReader.GetDatabaseDefinition(); var comparer = new Comparer(SqlExecuterTestAdapter.GetContext(version)); changes = comparer.Compare(ddInDatabase, dds.New); var databaseMigrator = new DatabaseMigrator(SqlExecuterTestAdapter.GetExecuter(version.UniqueName), SqlGeneratorFactory.CreateMigrationGenerator(version, SqlExecuterTestAdapter.GetContext(version))); return(databaseMigrator); }
public void ReadTables(SqlEngineVersion version) { Init(version, null); TestHelper.CheckFeature(version, "ReadDdl"); var dd = new ForeignKeyComposite(); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(_sqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], _sqlExecuterTestAdapter.GetContext(version), dd.GetSchemaNames().ToList()); var db = ddlReader.GetDatabaseDefinition(); var company = db.GetTable("Company"); var pkCompany = company.Properties.OfType <PrimaryKey>().FirstOrDefault(); Assert.IsNotNull(pkCompany); Assert.AreEqual(1, pkCompany.SqlColumns.Count); Assert.AreEqual("Id", pkCompany.SqlColumns[0].SqlColumn.Name); var topOrdersPerCompany = db.GetTable("TopOrdersPerCompany"); var fks = topOrdersPerCompany.Properties.OfType <ForeignKey>().ToList(); Assert.AreEqual(2, fks.Count); var fk1 = fks[0]; var fk2 = fks[1]; Assert.AreEqual(2, fk1.ForeignKeyColumns.Count); Assert.AreEqual(2, fk2.ForeignKeyColumns.Count); var order = db.GetTable("Order"); Assert.AreEqual(topOrdersPerCompany.Columns["Top1A"], fk1.ForeignKeyColumns[0].ForeignKeyColumn); Assert.AreEqual(topOrdersPerCompany.Columns["Top1B"], fk1.ForeignKeyColumns[1].ForeignKeyColumn); Assert.AreEqual(order.Columns["OrderHeaderId"], fk1.ForeignKeyColumns[0].ReferredColumn); Assert.AreEqual(order.Columns["LineNumber"], fk1.ForeignKeyColumns[1].ReferredColumn); Assert.AreEqual(topOrdersPerCompany.Columns["Top2A"], fk2.ForeignKeyColumns[0].ForeignKeyColumn); Assert.AreEqual(topOrdersPerCompany.Columns["Top2B"], fk2.ForeignKeyColumns[1].ForeignKeyColumn); Assert.AreEqual(order.Columns["OrderHeaderId"], fk2.ForeignKeyColumns[0].ReferredColumn); Assert.AreEqual(order.Columns["LineNumber"], fk2.ForeignKeyColumns[1].ReferredColumn); }
public override void Pk_Add(SqlEngineVersion version) { var dds = Pk_Add_Dds(version); var databaseMigrator = ProcessAndGetMigrator(version, dds, out var changes); var primaryKeyNew = changes[0] as PrimaryKeyNew; databaseMigrator.NewPrimaryKey(primaryKeyNew); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(SqlExecuterTestAdapter.ConnectionStrings[version.UniqueName], SqlExecuterTestAdapter.GetContext(version), dds.Original.GetSchemaNames().ToList()); var ddInDatabase = ddlReader.GetDatabaseDefinition(); var newPk = ddInDatabase.GetTable("Company").Properties.OfType <PrimaryKey>().First(); Assert.AreEqual(1, newPk.SqlColumns.Count); Assert.AreEqual("Id", newPk.SqlColumns[0].SqlColumn.Name); Assert.AreEqual("PK_Company", newPk.Name, true, CultureInfo.InvariantCulture); }
public void Check( [Option(LongName = "connectionString", ShortName = "c")] string connectionString, [Option(LongName = "sqlType", ShortName = "t")] string sqlType, [Option(LongName = "patternFileName", ShortName = "p")] string patternFileName, [Option(LongName = "flags", ShortName = "f")] List <string> flags) { var version = SqlEngineVersions.GetVersion(sqlType); var connString = new NamedConnectionString( version.GetType().Name, version.ProviderName, connectionString, version.VersionString); var context = CreateContext(version); var sqlExecuter = SqlExecuterFactory.CreateSqlExecuter(connString, context); var databaseName = sqlExecuter.GetDatabase(); var ddlReader = DataDefinitionReaderFactory.CreateDataDefinitionReader(connString, context, null); var dd = ddlReader.GetDatabaseDefinition(); var documenterContext = CreateDocumenterContext(context, patternFileName); if (flags != null) { SetSettingsFromFlags(flags, documenterContext.DocumenterSettings); } var schemaCheckerDocumenter = new SchemaCheckerDocumenter(documenterContext, version, databaseName, null); schemaCheckerDocumenter.Document(dd); }
public void ChangeDocument( [Option(LongName = "connectionStringOriginal")] string connectionStringOriginal, [Option(LongName = "connectionStringNew")] string connectionStringNew, [Option(LongName = "sqlTypeOriginal")] string sqlTypeOriginal, [Option(LongName = "sqlTypeNew")] string sqlTypeNew, [Option(LongName = "patternFileName", ShortName = "p")] string patternFileName, [Option(LongName = "patternFileNameOriginal")] string patternFileNameOriginal, [Option(LongName = "patternFileNameNew")] string patternFileNameNew, [Option(LongName = "flags", ShortName = "f")] List <string> flags) { var versionOriginal = SqlEngineVersions.GetVersion(sqlTypeOriginal); var contextOriginal = CreateContext(versionOriginal); var connString = new NamedConnectionString( versionOriginal.GetType().Name, versionOriginal.ProviderName, connectionStringOriginal, versionOriginal.VersionString); var sqlExecuterOriginal = SqlExecuterFactory.CreateSqlExecuter(connString, contextOriginal); var databaseNameOriginal = sqlExecuterOriginal.GetDatabase(); var ddlReaderOriginal = DataDefinitionReaderFactory.CreateDataDefinitionReader(connString, contextOriginal, null); //var ddOriginal = ddlReaderOriginal.GetDatabaseDefinition(); var ddOriginalTask = Task.Run(() => ddlReaderOriginal.GetDatabaseDefinition()); if (patternFileNameOriginal == null) { patternFileNameOriginal = patternFileName; } if (patternFileNameNew == null) { patternFileNameNew = patternFileName; } var changeDocumenterContext = CreateChangeDocumenterContext(contextOriginal, patternFileNameOriginal, patternFileNameNew); if (flags != null) { SetSettingsFromFlags(flags, changeDocumenterContext.DocumenterSettings); } var versionNew = SqlEngineVersions.GetVersion(sqlTypeNew); var contextNew = CreateContext(versionNew); var connStringNew = new NamedConnectionString( versionNew.GetType().Name, versionNew.ProviderName, connectionStringNew, versionNew.VersionString); var sqlExecuterNew = SqlExecuterFactory.CreateSqlExecuter(connStringNew, contextNew); var databaseNameNew = sqlExecuterNew.GetDatabase(); var ddlReaderNew = DataDefinitionReaderFactory.CreateDataDefinitionReader(connStringNew, contextNew, null); //var ddNew = ddlReaderNew.GetDatabaseDefinition(); var ddNewTask = Task.Run(() => ddlReaderNew.GetDatabaseDefinition()); var changeDocumenter = new ChangeDocumenter(changeDocumenterContext, versionOriginal, databaseNameOriginal, databaseNameNew); var ddOriginal = ddOriginalTask.Result; var ddNew = ddNewTask.Result; changeDocumenter.Document(ddOriginal, ddNew); }