From 89312a81c20b1e33a28cbef5e0b8b6677808b611 Mon Sep 17 00:00:00 2001 From: martinjw Date: Fri, 30 Jul 2021 11:49:39 +0200 Subject: [PATCH] #123 escapeNames not correctly passed down postgresql indexes --- CopyToSQLite/Properties/AssemblyInfo.cs | 4 +-- .../DatabaseSchemaReader.csproj | 3 +- .../Properties/AssemblyInfo.cs | 4 +-- .../SqlGen/Db2/TableGenerator.cs | 2 +- .../SqlGen/MySql/TableGenerator.cs | 2 +- .../SqlGen/PostgreSql/TableGenerator.cs | 2 +- .../SqlGen/SqlServer/TableGenerator.cs | 1 + .../DatabaseSchemaReaderTest.csproj | 1 + .../SqlGen/PostgreSql/GeneratorTest.cs | 34 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 4 +-- 10 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 DatabaseSchemaReaderTest/SqlGen/PostgreSql/GeneratorTest.cs diff --git a/CopyToSQLite/Properties/AssemblyInfo.cs b/CopyToSQLite/Properties/AssemblyInfo.cs index 6d6e3e8a..6cf8a2db 100644 --- a/CopyToSQLite/Properties/AssemblyInfo.cs +++ b/CopyToSQLite/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.8.0")] -[assembly: AssemblyFileVersion("2.7.8.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.7.9.0")] +[assembly: AssemblyFileVersion("2.7.9.0")] \ No newline at end of file diff --git a/DatabaseSchemaReader/DatabaseSchemaReader.csproj b/DatabaseSchemaReader/DatabaseSchemaReader.csproj index e1f0e51b..28dfbad9 100644 --- a/DatabaseSchemaReader/DatabaseSchemaReader.csproj +++ b/DatabaseSchemaReader/DatabaseSchemaReader.csproj @@ -3,7 +3,7 @@ Any ADO provider can be read (SqlServer, SqlServer CE 4, MySQL, SQLite, System.Data.OracleClient, ODP, Devart, PostgreSql, DB2...) into a single standard model. DatabaseSchemaReader - 2.7.8 + 2.7.9 Martin Willey netstandard2.0;netstandard1.5;net45;net40;net35 true @@ -17,6 +17,7 @@ 2.7.6: PostgreSql MigrationGenerator cascade escaping thanks @groogiam 2.7.7: fixes null 'RefersToTable' of FK when only one table is read thanks @mjalil 2.7.8: PostgreSql sequences missing thanks @groogiam +2.7.9: PostgreSql sqlgen escaping thanks @r-work https://github.com/martinjw/dbschemareader http://www.microsoft.com/en-us/openness/licenses.aspx#MPL diff --git a/DatabaseSchemaReader/Properties/AssemblyInfo.cs b/DatabaseSchemaReader/Properties/AssemblyInfo.cs index ffe6b991..3324986d 100644 --- a/DatabaseSchemaReader/Properties/AssemblyInfo.cs +++ b/DatabaseSchemaReader/Properties/AssemblyInfo.cs @@ -32,7 +32,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.8.0")] -[assembly: AssemblyFileVersion("2.7.8.0")] +[assembly: AssemblyVersion("2.7.9.0")] +[assembly: AssemblyFileVersion("2.7.9.0")] [assembly: CLSCompliant(true)] [assembly: InternalsVisibleTo("DatabaseSchemaReaderTest")] \ No newline at end of file diff --git a/DatabaseSchemaReader/SqlGen/Db2/TableGenerator.cs b/DatabaseSchemaReader/SqlGen/Db2/TableGenerator.cs index a76e8097..1a567cf4 100644 --- a/DatabaseSchemaReader/SqlGen/Db2/TableGenerator.cs +++ b/DatabaseSchemaReader/SqlGen/Db2/TableGenerator.cs @@ -89,7 +89,7 @@ protected override string ConstraintWriter() } protected virtual IMigrationGenerator CreateMigrationGenerator() { - return new Db2MigrationGenerator { IncludeSchema = IncludeSchema }; + return new Db2MigrationGenerator { IncludeSchema = IncludeSchema, EscapeNames = EscapeNames}; } private void AddIndexes(StringBuilder sb) { diff --git a/DatabaseSchemaReader/SqlGen/MySql/TableGenerator.cs b/DatabaseSchemaReader/SqlGen/MySql/TableGenerator.cs index c20d9518..06f07eea 100644 --- a/DatabaseSchemaReader/SqlGen/MySql/TableGenerator.cs +++ b/DatabaseSchemaReader/SqlGen/MySql/TableGenerator.cs @@ -100,7 +100,7 @@ protected override string ConstraintWriter() } protected virtual IMigrationGenerator CreateMigrationGenerator() { - return new MySqlMigrationGenerator { IncludeSchema = IncludeSchema }; + return new MySqlMigrationGenerator { IncludeSchema = IncludeSchema, EscapeNames = EscapeNames}; } private void AddIndexes(StringBuilder sb) { diff --git a/DatabaseSchemaReader/SqlGen/PostgreSql/TableGenerator.cs b/DatabaseSchemaReader/SqlGen/PostgreSql/TableGenerator.cs index d3986d90..1b7196aa 100644 --- a/DatabaseSchemaReader/SqlGen/PostgreSql/TableGenerator.cs +++ b/DatabaseSchemaReader/SqlGen/PostgreSql/TableGenerator.cs @@ -99,7 +99,7 @@ private static string TranslateCheckExpression(string expression) } protected virtual IMigrationGenerator CreateMigrationGenerator() { - return new PostgreSqlMigrationGenerator { IncludeSchema = IncludeSchema }; + return new PostgreSqlMigrationGenerator { IncludeSchema = IncludeSchema, EscapeNames = EscapeNames}; } private void AddIndexes(StringBuilder sb) { diff --git a/DatabaseSchemaReader/SqlGen/SqlServer/TableGenerator.cs b/DatabaseSchemaReader/SqlGen/SqlServer/TableGenerator.cs index 6c85e687..f4cf6ad3 100644 --- a/DatabaseSchemaReader/SqlGen/SqlServer/TableGenerator.cs +++ b/DatabaseSchemaReader/SqlGen/SqlServer/TableGenerator.cs @@ -104,6 +104,7 @@ protected virtual IMigrationGenerator CreateMigrationGenerator() var migrations = new SqlServerMigrationGenerator(); //ensure we're not writing schema prefixes if (!IncludeSchema) migrations.IncludeSchema = false; + migrations.EscapeNames = EscapeNames; return migrations; } diff --git a/DatabaseSchemaReaderTest/DatabaseSchemaReaderTest.csproj b/DatabaseSchemaReaderTest/DatabaseSchemaReaderTest.csproj index 6ae21af1..381347d5 100644 --- a/DatabaseSchemaReaderTest/DatabaseSchemaReaderTest.csproj +++ b/DatabaseSchemaReaderTest/DatabaseSchemaReaderTest.csproj @@ -298,6 +298,7 @@ + diff --git a/DatabaseSchemaReaderTest/SqlGen/PostgreSql/GeneratorTest.cs b/DatabaseSchemaReaderTest/SqlGen/PostgreSql/GeneratorTest.cs new file mode 100644 index 00000000..57c325e8 --- /dev/null +++ b/DatabaseSchemaReaderTest/SqlGen/PostgreSql/GeneratorTest.cs @@ -0,0 +1,34 @@ +using DatabaseSchemaReader.DataSchema; +using DatabaseSchemaReader.SqlGen; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace DatabaseSchemaReaderTest.SqlGen.PostgreSql +{ + [TestClass] + public class GeneratorTest + { + [TestMethod] + public void TestGeneratorEscaping() + { + //arrange + var schema = new DatabaseSchema(null, SqlType.PostgreSql); + var table = schema.AddTable("AllTypes") + .AddColumn("Id").AddIdentity() + .AddColumn("Name").AddLength(200) + .AddColumn("Age") + .AddColumn("Period") + .Table; + table.AddIndex("TableIndex", new[] { table.FindColumn("Name") }); + + var factory = new DdlGeneratorFactory(SqlType.PostgreSql); + var tableGen = factory.TableGenerator(table); + tableGen.EscapeNames = false; + + //act + var ddl = tableGen.Write(); + + //assert + Assert.IsTrue(ddl.Contains("INDEX TableIndex ON AllTypes(Name)")); + } + } +} \ No newline at end of file diff --git a/DatabaseSchemaViewer/Properties/AssemblyInfo.cs b/DatabaseSchemaViewer/Properties/AssemblyInfo.cs index 07b39805..9973e072 100644 --- a/DatabaseSchemaViewer/Properties/AssemblyInfo.cs +++ b/DatabaseSchemaViewer/Properties/AssemblyInfo.cs @@ -30,5 +30,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.7.8.0")] -[assembly: AssemblyFileVersion("2.7.8.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.7.9.0")] +[assembly: AssemblyFileVersion("2.7.9.0")] \ No newline at end of file