From d4473e8390982702d7ca9a115de73b29d0cad885 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 23 Jan 2024 14:55:49 +1000 Subject: [PATCH] Code cleanup --- README.md | 11 +++- src/.editorconfig | 16 +++--- src/Directory.Build.props | 34 +++++------ src/Tests/DatabaseSupportTests.cs | 3 +- src/Tests/NoPublicApiChanges.cs | 2 +- src/Tests/SqlCeSupportTests.cs | 38 ++++++------ src/Tests/Tests.csproj | 50 ++++++++-------- src/dbup-sqlce.sln.DotSettings | 25 +++++--- src/dbup-sqlce/SqlCeConnectionManager.cs | 29 +++++----- src/dbup-sqlce/SqlCeObjectParser.cs | 17 +++--- src/dbup-sqlce/SqlCePreprocessor.cs | 19 +++--- src/dbup-sqlce/SqlCeScriptExecutor.cs | 65 +++++++++++---------- src/dbup-sqlce/SqlCeTableJournal.cs | 73 ++++++++++++------------ src/dbup-sqlce/dbup-sqlce.csproj | 56 +++++++++--------- 14 files changed, 221 insertions(+), 217 deletions(-) diff --git a/README.md b/README.md index 8a8fdfe..fbd50b8 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,18 @@ [![Prerelease](https://img.shields.io/nuget/vpre/dbup-sqlce?color=orange&label=prerelease)](https://www.nuget.org/packages/dbup-sqlce) # DbUp SQL CE Support -DbUp is a .NET library that helps you to deploy changes to SQL Server databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date. + +DbUp is a .NET library that helps you to deploy changes to SQL Server databases. It tracks which SQL scripts have been +run already, and runs the change scripts that are needed to get your database up to date. ## Getting Help + To learn more about DbUp check out the [documentation](https://dbup.readthedocs.io/en/latest/) -Please only log issue related to SQL CE Support in this repo. For cross cutting issues, please use our [main issue list](https://github.com/DbUp/DbUp/issues). +Please only log issue related to SQL CE Support in this repo. For cross cutting issues, please use +our [main issue list](https://github.com/DbUp/DbUp/issues). # Contributing -See the [readme in our main repo](https://github.com/DbUp/DbUp/blob/master/README.md) for how to get started and contribute. \ No newline at end of file +See the [readme in our main repo](https://github.com/DbUp/DbUp/blob/master/README.md) for how to get started and +contribute. \ No newline at end of file diff --git a/src/.editorconfig b/src/.editorconfig index 3f25e8c..4363b48 100644 --- a/src/.editorconfig +++ b/src/.editorconfig @@ -48,14 +48,14 @@ dotnet_style_prefer_conditional_expression_over_return = true:silent # Naming Conventions # ############################### # Style Definitions -dotnet_naming_style.pascal_case_style.capitalization = pascal_case +dotnet_naming_style.pascal_case_style.capitalization = pascal_case # Use PascalCase for constant fields dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields -dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style -dotnet_naming_symbols.constant_fields.applicable_kinds = field -dotnet_naming_symbols.constant_fields.applicable_accessibilities = * -dotnet_naming_symbols.constant_fields.required_modifiers = const +dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields +dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style +dotnet_naming_symbols.constant_fields.applicable_kinds = field +dotnet_naming_symbols.constant_fields.applicable_accessibilities = * +dotnet_naming_symbols.constant_fields.required_modifiers = const ############################### # C# Coding Conventions # ############################### @@ -78,7 +78,7 @@ csharp_style_pattern_matching_over_as_with_null_check = true:suggestion csharp_style_throw_expression = true:suggestion csharp_style_conditional_delegate_call = true:suggestion # Modifier preferences -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion +csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:suggestion # Expression-level preferences csharp_prefer_braces = when_multiline:suggestion csharp_style_deconstructed_variable_declaration = true:suggestion @@ -120,4 +120,4 @@ csharp_preserve_single_line_blocks = true ############################### [*.vb] # Modifier preferences -visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion +visual_basic_preferred_modifier_order = Partial, Default, Private, Protected, Public, Friend, NotOverridable, Overridable, MustOverride, Overloads, Overrides, MustInherit, NotInheritable, Static, Shared, Shadows, ReadOnly, WriteOnly, Dim, Const, WithEvents, Widening, Narrowing, Custom, Async:suggestion diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 4e56146..19b01a7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,27 +1,27 @@  - - https://github.com/orgs/DbUp/people - https://github.com/DbUp/dbup-sqlce/releases - https://dbup.github.io - MIT - https://github.com/dbup-sqlce/dbup-sqlce.git - latest - true - + + https://github.com/orgs/DbUp/people + https://github.com/DbUp/dbup-sqlce/releases + https://dbup.github.io + MIT + https://github.com/dbup-sqlce/dbup-sqlce.git + latest + true + - + - - true + + true - - true + + true - - embedded + + embedded - + diff --git a/src/Tests/DatabaseSupportTests.cs b/src/Tests/DatabaseSupportTests.cs index a2d6d2c..77cea9d 100644 --- a/src/Tests/DatabaseSupportTests.cs +++ b/src/Tests/DatabaseSupportTests.cs @@ -1,9 +1,8 @@ #if !NETCORE using DbUp.Builder; -using DbUp.SqlCe; using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.SqlCe; +namespace DbUp.SqlCe.Tests; public class DatabaseSupportTests : DatabaseSupportTestsBase { diff --git a/src/Tests/NoPublicApiChanges.cs b/src/Tests/NoPublicApiChanges.cs index a0fe7d4..b089b04 100644 --- a/src/Tests/NoPublicApiChanges.cs +++ b/src/Tests/NoPublicApiChanges.cs @@ -1,7 +1,7 @@ #if !NETCORE using DbUp.Tests.Common; -namespace DbUp.Tests.Providers.SqlCe; +namespace DbUp.SqlCe.Tests; public class NoPublicApiChanges : NoPublicApiChangesBase { diff --git a/src/Tests/SqlCeSupportTests.cs b/src/Tests/SqlCeSupportTests.cs index c4b0b48..0f8d0a6 100644 --- a/src/Tests/SqlCeSupportTests.cs +++ b/src/Tests/SqlCeSupportTests.cs @@ -1,35 +1,33 @@ #if !NETCORE -using System; using System.Data.SqlServerCe; using System.IO; using Shouldly; using Xunit; -namespace DbUp.Tests.Support.SqlCe +namespace DbUp.SqlCe.Tests; + +public class SqlCeSupportTests { - public class SqlCeSupportTests + [Fact] + public void CanUseSqlCe4() { - [Fact] - public void CanUseSqlCe4() - { - const string connectionString = "Data Source=test.sdf; Persist Security Info=False"; + const string connectionString = "Data Source=test.sdf; Persist Security Info=False"; - if (!File.Exists("test.sdf")) - { - var engine = new SqlCeEngine(connectionString); - engine.CreateDatabase(); - } + if (!File.Exists("test.sdf")) + { + var engine = new SqlCeEngine(connectionString); + engine.CreateDatabase(); + } - //Verify supports scripts which specify schema (To Support SqlCe and Sql with Schemas) - var upgrader = DeployChanges.To - .SqlCeDatabase(connectionString) - .WithScript("Script0001", "create table $schema$.Foo (Id int)") - .Build(); + //Verify supports scripts which specify schema (To Support SqlCe and Sql with Schemas) + var upgrader = DeployChanges.To + .SqlCeDatabase(connectionString) + .WithScript("Script0001", "create table $schema$.Foo (Id int)") + .Build(); - var result = upgrader.PerformUpgrade(); + var result = upgrader.PerformUpgrade(); - result.Successful.ShouldBe(true); - } + result.Successful.ShouldBe(true); } } #endif \ No newline at end of file diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index dd800c4..47b64d7 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -1,30 +1,30 @@ - - net462 - Tests - DbUp.SqlCe.Tests - true - - enable - $(NoWarn);NETSDK1138 - latest - + + net462 + Tests + DbUp.SqlCe.Tests + true + + enable + $(NoWarn);NETSDK1138 + latest + - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + - - - - - diff --git a/src/dbup-sqlce.sln.DotSettings b/src/dbup-sqlce.sln.DotSettings index 2c78c0a..6f7d84b 100644 --- a/src/dbup-sqlce.sln.DotSettings +++ b/src/dbup-sqlce.sln.DotSettings @@ -1,9 +1,16 @@ - - DO_NOT_SHOW - Implicit - Implicit - SQ - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> - <data><IncludeFilters /><ExcludeFilters /></data> - <data /> \ No newline at end of file + + DO_NOT_SHOW + Implicit + Implicit + SQ + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <data><IncludeFilters /><ExcludeFilters /></data> + <data /> \ No newline at end of file diff --git a/src/dbup-sqlce/SqlCeConnectionManager.cs b/src/dbup-sqlce/SqlCeConnectionManager.cs index fd06f7c..f9f31de 100644 --- a/src/dbup-sqlce/SqlCeConnectionManager.cs +++ b/src/dbup-sqlce/SqlCeConnectionManager.cs @@ -3,26 +3,25 @@ using DbUp.Engine.Transactions; using DbUp.Support; -namespace DbUp.SqlCe +namespace DbUp.SqlCe; + +/// +/// Manages SqlCe Database Connections +/// +public class SqlCeConnectionManager : DatabaseConnectionManager { /// /// Manages SqlCe Database Connections /// - public class SqlCeConnectionManager : DatabaseConnectionManager + /// + public SqlCeConnectionManager(string connectionString) : base(l => new SqlCeConnection(connectionString)) { - /// - /// Manages SqlCe Database Connections - /// - /// - public SqlCeConnectionManager(string connectionString) : base(l => new SqlCeConnection(connectionString)) - { - } + } - public override IEnumerable SplitScriptIntoCommands(string scriptContents) - { - var commandSplitter = new SqlCommandSplitter(); - var scriptStatements = commandSplitter.SplitScriptIntoCommands(scriptContents); - return scriptStatements; - } + public override IEnumerable SplitScriptIntoCommands(string scriptContents) + { + var commandSplitter = new SqlCommandSplitter(); + var scriptStatements = commandSplitter.SplitScriptIntoCommands(scriptContents); + return scriptStatements; } } diff --git a/src/dbup-sqlce/SqlCeObjectParser.cs b/src/dbup-sqlce/SqlCeObjectParser.cs index 27f85fd..834346a 100644 --- a/src/dbup-sqlce/SqlCeObjectParser.cs +++ b/src/dbup-sqlce/SqlCeObjectParser.cs @@ -1,14 +1,13 @@ using DbUp.Support; -namespace DbUp.SqlCe +namespace DbUp.SqlCe; + +/// +/// Parses Sql Objects and performs quoting functions. +/// +public class SqlCeObjectParser : SqlObjectParser { - /// - /// Parses Sql Objects and performs quoting functions. - /// - public class SqlCeObjectParser : SqlObjectParser + public SqlCeObjectParser() : base("[", "]") { - public SqlCeObjectParser() : base("[", "]") - { - } } -} +} \ No newline at end of file diff --git a/src/dbup-sqlce/SqlCePreprocessor.cs b/src/dbup-sqlce/SqlCePreprocessor.cs index 5c6cdc3..3ae4de2 100644 --- a/src/dbup-sqlce/SqlCePreprocessor.cs +++ b/src/dbup-sqlce/SqlCePreprocessor.cs @@ -1,19 +1,18 @@ using System.Text.RegularExpressions; using DbUp.Engine; -namespace DbUp.SqlCe +namespace DbUp.SqlCe; + +/// +/// This preprocessor makes minor adjustments to your sql to make it compatible with SqlCe. +/// +public class SqlCePreprocessor : IScriptPreprocessor { /// - /// This preprocessor makes minor adjustments to your sql to make it compatible with SqlCe. + /// Performs some preprocessing step on a script /// - public class SqlCePreprocessor : IScriptPreprocessor + public string Process(string contents) { - /// - /// Performs some preprocessing step on a script - /// - public string Process(string contents) - { - return Regex.Replace(contents, @"nvarchar\s?\(max\)", "ntext", RegexOptions.IgnoreCase); - } + return Regex.Replace(contents, @"nvarchar\s?\(max\)", "ntext", RegexOptions.IgnoreCase); } } \ No newline at end of file diff --git a/src/dbup-sqlce/SqlCeScriptExecutor.cs b/src/dbup-sqlce/SqlCeScriptExecutor.cs index a4a8a0e..fa41fb7 100644 --- a/src/dbup-sqlce/SqlCeScriptExecutor.cs +++ b/src/dbup-sqlce/SqlCeScriptExecutor.cs @@ -6,46 +6,45 @@ using DbUp.Engine.Transactions; using DbUp.Support; -namespace DbUp.SqlCe +namespace DbUp.SqlCe; + +/// +/// An implementation of that executes against a SqlCe database. +/// +public class SqlCeScriptExecutor : ScriptExecutor { /// - /// An implementation of that executes against a SqlCe database. + /// Initializes an instance of the class. /// - public class SqlCeScriptExecutor : ScriptExecutor + /// + /// The logging mechanism. + /// The schema that contains the table. + /// Function that returns true if variables should be replaced, false otherwise. + /// Script Preprocessors in addition to variable substitution + /// Database journal + public SqlCeScriptExecutor(Func connectionManagerFactory, Func log, string schema, Func variablesEnabled, + IEnumerable scriptPreprocessors, Func journal) + : base(connectionManagerFactory, new SqlCeObjectParser(), log, schema, variablesEnabled, scriptPreprocessors, journal) { - /// - /// Initializes an instance of the class. - /// - /// - /// The logging mechanism. - /// The schema that contains the table. - /// Function that returns true if variables should be replaced, false otherwise. - /// Script Preprocessors in addition to variable substitution - /// Database journal - public SqlCeScriptExecutor(Func connectionManagerFactory, Func log, string schema, Func variablesEnabled, - IEnumerable scriptPreprocessors, Func journal) - : base(connectionManagerFactory, new SqlCeObjectParser(), log, schema, variablesEnabled, scriptPreprocessors, journal) - { - } + } - protected override string GetVerifySchemaSql(string schema) + protected override string GetVerifySchemaSql(string schema) + { + throw new NotSupportedException(); + } + + protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScript script, Action executeCommand) + { + try { - throw new NotSupportedException(); + executeCommand(); } - - protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScript script, Action executeCommand) + catch (SqlCeException exception) { - try - { - executeCommand(); - } - catch (SqlCeException exception) - { - Log().WriteInformation("SqlCe exception has occured in script: '{0}'", script.Name); - Log().WriteError("Script block number: {0}; Native Error: {1}; Message: {2}", index, exception.NativeError, exception.Message); - Log().WriteError(exception.ToString()); - throw; - } + Log().WriteInformation("SqlCe exception has occured in script: '{0}'", script.Name); + Log().WriteError("Script block number: {0}; Native Error: {1}; Message: {2}", index, exception.NativeError, exception.Message); + Log().WriteError(exception.ToString()); + throw; } } -} +} \ No newline at end of file diff --git a/src/dbup-sqlce/SqlCeTableJournal.cs b/src/dbup-sqlce/SqlCeTableJournal.cs index 895c57c..f8653fb 100644 --- a/src/dbup-sqlce/SqlCeTableJournal.cs +++ b/src/dbup-sqlce/SqlCeTableJournal.cs @@ -4,55 +4,54 @@ using DbUp.Engine.Transactions; using DbUp.Support; -namespace DbUp.SqlCe +namespace DbUp.SqlCe; + +/// +/// An implementation of the interface which tracks version numbers for a +/// Sql Server Ce database using a table called dbo.SchemaVersions. +/// +public class SqlCeTableJournal : TableJournal { /// - /// An implementation of the interface which tracks version numbers for a - /// Sql Server Ce database using a table called dbo.SchemaVersions. + /// Initializes a new instance of the class. /// - public class SqlCeTableJournal : TableJournal + /// The connection manager. + /// The log. + /// The schema that contains the table. + /// The table name. + /// + /// var journal = new TableJournal("Server=server;Database=database;Trusted_Connection=True", "dbo", "MyVersionTable"); + /// + public SqlCeTableJournal(Func connectionManager, Func logger, string schema, string table) + : base(connectionManager, logger, new SqlCeObjectParser(), schema, table) { - /// - /// Initializes a new instance of the class. - /// - /// The connection manager. - /// The log. - /// The schema that contains the table. - /// The table name. - /// - /// var journal = new TableJournal("Server=server;Database=database;Trusted_Connection=True", "dbo", "MyVersionTable"); - /// - public SqlCeTableJournal(Func connectionManager, Func logger, string schema, string table) - : base(connectionManager, logger, new SqlCeObjectParser(), schema, table) - { - } + } - protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) - { - return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})"; - } + protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) + { + return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})"; + } - protected override string GetJournalEntriesSql() - { - return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]"; - } + protected override string GetJournalEntriesSql() + { + return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]"; + } - protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) - { - return -$@"create table {FqSchemaTableName} ( + protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) + { + return + $@"create table {FqSchemaTableName} ( [Id] int identity(1,1) not null constraint {quotedPrimaryKeyName} primary key, [ScriptName] nvarchar(255) not null, [Applied] datetime not null )"; - } + } - protected override string DoesTableExistSql() - { - if (string.IsNullOrEmpty(SchemaTableSchema)) - return $"SELECT count(*) FROM information_schema.tables WHERE table_name='{UnquotedSchemaTableName}'"; + protected override string DoesTableExistSql() + { + if (string.IsNullOrEmpty(SchemaTableSchema)) + return $"SELECT count(*) FROM information_schema.tables WHERE table_name='{UnquotedSchemaTableName}'"; - return $"SELECT count(*) FROM information_schema.tables WHERE table_schema = '{SchemaTableSchema}'AND table_name = '{UnquotedSchemaTableName}')"; - } + return $"SELECT count(*) FROM information_schema.tables WHERE table_schema = '{SchemaTableSchema}'AND table_name = '{UnquotedSchemaTableName}')"; } } \ No newline at end of file diff --git a/src/dbup-sqlce/dbup-sqlce.csproj b/src/dbup-sqlce/dbup-sqlce.csproj index f386291..9dda2f3 100644 --- a/src/dbup-sqlce/dbup-sqlce.csproj +++ b/src/dbup-sqlce/dbup-sqlce.csproj @@ -1,36 +1,36 @@  - - DbUp makes it easy to deploy and upgrade SQL Server databases. This package adds SQL CE Support. - DbUp SQL CE Support - net462 - DbUp.SqlCe - ../dbup.snk - true - false - false - false - https://github.com/DbUp/dbup-sqlce.git - dbup_sqlce - dbup-sqlce - dbup-icon.png - + + DbUp makes it easy to deploy and upgrade SQL Server databases. This package adds SQL CE Support. + DbUp SQL CE Support + net462 + DbUp.SqlCe + ../dbup.snk + true + false + false + false + https://github.com/DbUp/dbup-sqlce.git + dbup_sqlce + dbup-sqlce + dbup-icon.png + - - - - + + + + - - - + + + - - - + + + - - - + + +