From 56d5c464e3d8155a0311103f6ee1729d4cc3c7a6 Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Tue, 30 Jan 2024 20:57:14 +1000 Subject: [PATCH 1/9] fix(driverResolve Exception during PerformUpgrade using LogScriptOutput #577 - Drop non supported frames. (Netstandard 1.3/Mono) - Replace System.Data.SQLite with Microsoft.Data.SqLite - Breaking change `Create` removed from TemporarySQLiteDatabase, it is now implicit --- src/Sample/Program.cs | 5 +- .../NoPublicApiChanges.Run.DotNet.verified.cs | 1 - .../NoPublicApiChanges.Run.Net.verified.cs | 1 - src/Tests/SQLiteSupportTests.cs | 37 +++++++++----- src/Tests/SQLiteTableJournalTests.cs | 8 ++- .../Helpers/InMemorySQLiteDatabase.cs | 30 +++-------- .../Helpers/TemporarySQLiteDatabase.cs | 50 ++----------------- src/dbup-sqlite/SQLiteConnectionManager.cs | 12 ++--- src/dbup-sqlite/SQLiteScriptExecutor.cs | 15 +----- src/dbup-sqlite/dbup-sqlite.csproj | 13 +---- 10 files changed, 48 insertions(+), 124 deletions(-) diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs index 8957155..3ff2c46 100644 --- a/src/Sample/Program.cs +++ b/src/Sample/Program.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Data.Sqlite; namespace SQLiteSampleApplication { @@ -55,7 +56,7 @@ static void TemporaryFileDb() static void PermanentFileDb() { - Microsoft.Data.Sqlite.SqliteConnection connection = new("Data Source=dbup.db"); + SqliteConnection connection = new("Data Source=dbup.db"); using (var database = new DbUp.SQLite.Helpers.SharedConnection(connection)) { @@ -98,4 +99,4 @@ static void Display(string dbType, DbUp.Engine.DatabaseUpgradeResult result, Tim } } } -} \ No newline at end of file +} diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs index 15ac3ed..b691b30 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs @@ -71,7 +71,6 @@ public class TemporarySQLiteDatabase : System.IDisposable public TemporarySQLiteDatabase(string name) { } public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } - public void Create() { } public void Dispose() { } } } diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs index 15ac3ed..b691b30 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs @@ -71,7 +71,6 @@ public class TemporarySQLiteDatabase : System.IDisposable public TemporarySQLiteDatabase(string name) { } public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } - public void Create() { } public void Dispose() { } } } diff --git a/src/Tests/SQLiteSupportTests.cs b/src/Tests/SQLiteSupportTests.cs index bd0d553..b6cafe4 100644 --- a/src/Tests/SQLiteSupportTests.cs +++ b/src/Tests/SQLiteSupportTests.cs @@ -1,30 +1,43 @@ -#if !NETCORE -using System; -using System.Data.SQLite; +using System; using System.IO; +using Shouldly; using Xunit; namespace DbUp.SQLite.Tests { public class SQLiteSupportTests { - static readonly string dbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db"); + static readonly string DbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db"); [Fact] public void CanUseSQLite() { - var connectionString = string.Format("Data Source={0}; Version=3;", dbFilePath); + var connectionString = $"Data Source={DbFilePath}; Version=3;"; - if (!File.Exists(dbFilePath)) - { - SQLiteConnection.CreateFile(dbFilePath); - } - - var upgrader = DeployChanges.To + DeployChanges.To .SQLiteDatabase(connectionString) .WithScript("Script0001", "CREATE TABLE IF NOT EXISTS Foo (Id int)") .Build(); } + + [Fact] + public void DoesNotExhibitSafeHandleError_Issue577() + { + var connectionString = "Data source=:memory:"; + + var upgrader = + DeployChanges.To + .SQLiteDatabase(connectionString) + .WithScript("Script001", @" +create table test ( + contact_id INTEGER PRIMARY KEY +); +") + .LogScriptOutput() + .LogToConsole() + .Build(); + var result = upgrader.PerformUpgrade(); + result.Successful.ShouldBeTrue(); + } } } -#endif diff --git a/src/Tests/SQLiteTableJournalTests.cs b/src/Tests/SQLiteTableJournalTests.cs index ce0171a..2b02260 100644 --- a/src/Tests/SQLiteTableJournalTests.cs +++ b/src/Tests/SQLiteTableJournalTests.cs @@ -1,11 +1,10 @@ -#if !NETCORE -using System.Collections.Generic; +using System.Collections.Generic; using System.Data; -using System.Data.SQLite; using DbUp.Engine; using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.Tests.Common; +using Microsoft.Data.Sqlite; using NSubstitute; using Shouldly; using Xunit; @@ -22,7 +21,7 @@ public void dbversion_is_zero_when_journal_table_not_exist() var command = Substitute.For(); dbConnection.CreateCommand().Returns(command); var connectionManager = Substitute.For(); - command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); }); + command.ExecuteScalar().Returns(x => throw new SqliteException("table not found",1)); var consoleUpgradeLog = new ConsoleUpgradeLog(); var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); @@ -62,4 +61,3 @@ public void creates_a_new_journal_table_when_not_exist() } } } -#endif diff --git a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs index 16bec7b..86bd9f1 100644 --- a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs @@ -1,17 +1,7 @@ using System; using DbUp.Engine.Transactions; using DbUp.Helpers; - -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Mono.Data.Sqlite.SqliteConnectionStringBuilder; -using SQLiteJournalModeEnum = Mono.Data.Sqlite.SQLiteJournalModeEnum; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Microsoft.Data.Sqlite.SqliteConnectionStringBuilder; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite.Helpers { @@ -21,31 +11,23 @@ namespace DbUp.SQLite.Helpers public class InMemorySQLiteDatabase : IDisposable { readonly SQLiteConnectionManager connectionManager; - readonly SQLiteConnection sharedConnection; + readonly SqliteConnection sharedConnection; /// /// Initializes a new instance of the class. /// public InMemorySQLiteDatabase() { - var connectionStringBuilder = new SQLiteConnectionStringBuilder + var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:", -#if !NETCORE - Version = 3, - DefaultTimeout = 5, -#if MONO - JournalMode = SQLiteJournalModeEnum.Off, -#else - JournalMode = SQLiteJournalModeEnum.Memory, -#endif - UseUTF16Encoding = true -#endif + Mode = SqliteOpenMode.Memory, + ConnectionString = "PRAGMA encoding='UTF-16'; PRAGMA journal_mode='MEMORY';" }; ConnectionString = connectionStringBuilder.ToString(); connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString); - sharedConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); + sharedConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sharedConnection.Open(); SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); } diff --git a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs index e1d1911..c69d69b 100644 --- a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs @@ -1,17 +1,7 @@ using System; using System.IO; using DbUp.Helpers; - -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Mono.Data.Sqlite.SqliteConnectionStringBuilder; -using SQLiteJournalModeEnum = Mono.Data.Sqlite.SQLiteJournalModeEnum; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Microsoft.Data.Sqlite.SqliteConnectionStringBuilder; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite.Helpers { @@ -21,7 +11,7 @@ namespace DbUp.SQLite.Helpers public class TemporarySQLiteDatabase : IDisposable { readonly string dataSourcePath; - readonly SQLiteConnection sqLiteConnection; + readonly SqliteConnection sqLiteConnection; /// /// Initializes a new instance of the class. @@ -31,22 +21,12 @@ public TemporarySQLiteDatabase(string name) { dataSourcePath = Path.Combine(Directory.GetCurrentDirectory(), name); - var connectionStringBuilder = new SQLiteConnectionStringBuilder + var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = name, -#if !NETCORE - Version = 3, - DefaultTimeout = 5, -#if MONO - JournalMode = SQLiteJournalModeEnum.Off, -#else - JournalMode = SQLiteJournalModeEnum.Memory, -#endif - UseUTF16Encoding = true -#endif }; - sqLiteConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); + sqLiteConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sqLiteConnection.Open(); SharedConnection = new SharedConnection(sqLiteConnection); SqlRunner = new AdHocSqlRunner(() => sqLiteConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); @@ -59,20 +39,6 @@ public TemporarySQLiteDatabase(string name) public SharedConnection SharedConnection { get; } - /// - /// Creates the database. - /// - public void Create() - { -#if !NETCORE - var filePath = new FileInfo(dataSourcePath); - if (!filePath.Exists) - { - SQLiteConnection.CreateFile(dataSourcePath); - } -#endif - } - /// /// Deletes the database. /// @@ -82,14 +48,6 @@ public void Dispose() if (!filePath.Exists) return; SharedConnection.Dispose(); sqLiteConnection.Dispose(); -#if !NETCORE - SQLiteConnection.ClearAllPools(); - - // SQLite requires all created sql connection/command objects to be disposed - // in order to delete the database file - GC.Collect(2, GCCollectionMode.Forced); - System.Threading.Thread.Sleep(100); -#endif File.Delete(dataSourcePath); } } diff --git a/src/dbup-sqlite/SQLiteConnectionManager.cs b/src/dbup-sqlite/SQLiteConnectionManager.cs index 29f6edc..133ec6e 100644 --- a/src/dbup-sqlite/SQLiteConnectionManager.cs +++ b/src/dbup-sqlite/SQLiteConnectionManager.cs @@ -3,13 +3,7 @@ using System.Text.RegularExpressions; using DbUp.Engine.Transactions; using DbUp.SQLite.Helpers; -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite { @@ -21,7 +15,7 @@ public class SQLiteConnectionManager : DatabaseConnectionManager /// /// Creates new SQLite Connection Manager /// - public SQLiteConnectionManager(string connectionString) : base(l => new SQLiteConnection(connectionString)) + public SQLiteConnectionManager(string connectionString) : base(l => new SqliteConnection(connectionString)) { } @@ -46,4 +40,4 @@ public override IEnumerable SplitScriptIntoCommands(string scriptContent return scriptStatements; } } -} \ No newline at end of file +} diff --git a/src/dbup-sqlite/SQLiteScriptExecutor.cs b/src/dbup-sqlite/SQLiteScriptExecutor.cs index 741b52f..2476ac5 100644 --- a/src/dbup-sqlite/SQLiteScriptExecutor.cs +++ b/src/dbup-sqlite/SQLiteScriptExecutor.cs @@ -4,14 +4,7 @@ using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.Support; - -#if MONO -using SQLiteException = Mono.Data.Sqlite.SqliteException; -#elif NETCORE -using SQLiteException = Microsoft.Data.Sqlite.SqliteException; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite { @@ -46,14 +39,10 @@ protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScri { executeCommand(); } - catch (SQLiteException exception) + catch (SqliteException exception) { Log().WriteInformation("SQLite exception has occurred in script: '{0}'", script.Name); -#if NETCORE - Log().WriteError("Script block number: {0}; Error Code: {1}; Message: {2}", index, exception.SqliteErrorCode, exception.Message); -#else Log().WriteError("Script block number: {0}; Error Code: {1}; Message: {2}", index, exception.ErrorCode, exception.Message); -#endif Log().WriteError(exception.ToString()); throw; } diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index da35aad..36f8585 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -6,7 +6,7 @@ DbUp Contributors DbUp Copyright © DbUp Contributors 2015 - netstandard1.3;net462 + netstandard2.0;net462 dbup-sqlite DbUp.SQLite dbup-sqlite @@ -22,16 +22,7 @@ - - - - - - - - - - + From f3cfc2a3899434c22eaf00ba03159f729eef2512 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Sat, 20 Jul 2024 11:57:59 +1000 Subject: [PATCH 2/9] Used new GHA workflows --- .github/workflows/main.yml | 73 ++------------------------- .github/workflows/publish-release.yml | 12 +++++ .github/workflows/test-report.yml | 12 +++++ 3 files changed, 28 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/test-report.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18198a1..26798d9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,77 +2,12 @@ name: CI on: push: + branches: + - '**' # Ignores pushes of tags pull_request: workflow_dispatch: jobs: build: - runs-on: windows-latest # Use Ubuntu in v5.0 - - env: - DOTNET_NOLOGO: true - DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 # all - - - name: Setup .NET 2.0 # Remove in v5.0 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 2.0.x - - - name: Setup .NET 8.0 - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 8.0.x - - - name: Install GitVersion - uses: gittools/actions/gitversion/setup@v0 - with: - versionSpec: '5.x' - - - name: Run GitVersion - id: gitversion - uses: gittools/actions/gitversion/execute@v0 - - - name: Display SemVer - run: | - echo "SemVer: $env:GitVersion_SemVer" - - - name: Add DbUp NuGet Source - run: dotnet nuget add source --name DbUp --username DbUp --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text https://nuget.pkg.github.com/DbUp/index.json - - - name: Restore - run: dotnet restore - working-directory: src - - - name: Build - run: dotnet build -c Release --no-restore /p:Version=$env:GitVersion_SemVer - working-directory: src - - - name: Test - run: dotnet test --no-build -c Release --logger trx --logger "console;verbosity=detailed" --results-directory ../artifacts - working-directory: src - - - name: Pack - run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$env:GitVersion_SemVer - working-directory: src - - - name: Push NuGet packages to GitHub Packages ⬆️ - working-directory: artifacts - run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/DbUp/index.json" - - - name: Push NuGet packages to NuGet ⬆️ - if: ${{ steps.gitversion.outputs.preReleaseLabel == '' }} - working-directory: artifacts - run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json - - - name: Test Report 🧪 - uses: dorny/test-reporter@v1 - if: ${{ always() }} - with: - name: Tests - path: artifacts/*.trx - reporter: dotnet-trx + name: Build + uses: DbUp/Universe/.github/workflows/build.yml@main diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..eb5e03f --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,12 @@ +name: Publish DbUp Packages to NuGet + +on: + release: + types: [ published ] + workflow_dispatch: + +jobs: + publish: + name: Publish Package + uses: DbUp/Universe/.github/workflows/publish-release.yml@main + secrets: inherit diff --git a/.github/workflows/test-report.yml b/.github/workflows/test-report.yml new file mode 100644 index 0000000..e8c9f8f --- /dev/null +++ b/.github/workflows/test-report.yml @@ -0,0 +1,12 @@ +name: Test Report +run-name: Generate Test Report for run `${{ github.event.workflow_run.run_number }}` branch `${{ github.event.workflow_run.head_branch }}` + +on: + workflow_run: + workflows: ["CI", "build"] + types: [completed] + +jobs: + report: + name: Test Report 🧪 + uses: DbUp/Universe/.github/workflows/test-report.yml@main \ No newline at end of file From bb5cc6509d65c6c80fa55afb97a3374eb4b61262 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Thu, 25 Jul 2024 14:02:15 +1000 Subject: [PATCH 3/9] Updated to dbup-core 6.0 beta, targeted netstandard2 and update Sqlite reference --- src/Directory.Build.props | 14 ---- src/Sample/Program.cs | 4 +- src/Sample/Sample.csproj | 2 +- ...portTests.VerifyBasicSupport.approved.txt} | 4 +- ...JournalCreationIfNameChanged.approved.txt} | 4 +- ....VerifyVariableSubstitutions.approved.txt} | 4 +- .../NoPublicApiChanges.Run.DotNet.verified.cs | 77 ------------------- ....cs => NoPublicApiChanges.Run.approved.cs} | 1 - src/Tests/SQLiteSupportTests.cs | 19 ++--- src/Tests/SQLiteTableJournalTests.cs | 9 +-- src/Tests/Tests.csproj | 16 ++-- src/dbup-sqlite.sln.DotSettings | 3 + .../Helpers/InMemorySQLiteDatabase.cs | 26 +------ .../Helpers/TemporarySQLiteDatabase.cs | 49 ++---------- src/dbup-sqlite/SQLiteConnectionManager.cs | 12 +-- src/dbup-sqlite/SQLiteScriptExecutor.cs | 21 ++--- src/dbup-sqlite/dbup-sqlite.csproj | 21 ++--- 17 files changed, 56 insertions(+), 230 deletions(-) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyBasicSupport.verified.txt => DatabaseSupportTests.VerifyBasicSupport.approved.txt} (92%) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt => DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt} (92%) rename src/Tests/ApprovalFiles/{DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt => DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt} (92%) delete mode 100644 src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs rename src/Tests/ApprovalFiles/{NoPublicApiChanges.Run.Net.verified.cs => NoPublicApiChanges.Run.approved.cs} (99%) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index d3b79f1..db1e7b7 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -10,18 +10,4 @@ latest true - - - - - true - - - true - - - embedded - - - diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs index 8957155..90bc3e8 100644 --- a/src/Sample/Program.cs +++ b/src/Sample/Program.cs @@ -87,15 +87,17 @@ static void Display(string dbType, DbUp.Engine.DatabaseUpgradeResult result, Tim "{0} Database Upgrade Runtime: {1}", dbType, string.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 10)); + Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(result.Error); + Console.WriteLine("Press any key to continue..."); Console.ReadKey(); Console.WriteLine("Failed!"); } } } -} \ No newline at end of file +} diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj index df2f803..ad8a65c 100644 --- a/src/Sample/Sample.csproj +++ b/src/Sample/Sample.csproj @@ -1,6 +1,6 @@  - net8.0 + net8 Exe false diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt similarity index 92% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt index c49f705..df0e7a0 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt @@ -1,11 +1,11 @@ DB Operation: Open connection Info: Beginning database upgrade -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' DB Operation: Dispose command Info: Creating the [SchemaVersions] table diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt similarity index 92% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt index 9434571..ee2f20b 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt @@ -1,11 +1,11 @@ DB Operation: Open connection Info: Beginning database upgrade -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions' DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions' DB Operation: Dispose command Info: Creating the [TestSchemaVersions] table diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt similarity index 92% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt index 9bbd486..4bd02c0 100644 --- a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt +++ b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt @@ -1,11 +1,11 @@ DB Operation: Open connection Info: Beginning database upgrade -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' DB Operation: Dispose command Info: Journal table does not exist Info: Executing Database Server script 'Script0001.sql' -Info: Checking whether journal table exists.. +Info: Checking whether journal table exists DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' DB Operation: Dispose command Info: Creating the [SchemaVersions] table diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs deleted file mode 100644 index 15ac3ed..0000000 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs +++ /dev/null @@ -1,77 +0,0 @@ -[assembly: System.CLSCompliantAttribute(true)] -[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] -[assembly: System.Runtime.InteropServices.GuidAttribute("9f949414-f078-49bf-b50e-a3859c18fb6e")] - -public static class SQLiteExtensions -{ - public static DbUp.Builder.UpgradeEngineBuilder JournalToSQLiteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { } - public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } -} -namespace DbUp.SQLite -{ - public class SQLiteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager - { - public SQLiteConnectionManager(string connectionString) { } - public SQLiteConnectionManager(DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } - public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } - } - public class SQLiteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser - { - public SQLiteObjectParser() { } - } - public class SQLitePreprocessor : DbUp.Engine.IScriptPreprocessor - { - public SQLitePreprocessor() { } - public string Process(string contents) { } - } - public class SQLiteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor - { - public SQLiteScriptExecutor(System.Func connectionManagerFactory, System.Func log, string schema, System.Func variablesEnabled, System.Collections.Generic.IEnumerable scriptPreprocessors, System.Func journalFactory) { } - protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { } - protected override string GetVerifySchemaSql(string schema) { } - } - public class SQLiteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal - { - public SQLiteTableJournal(System.Func connectionManager, System.Func logger, string table) { } - protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { } - protected override string DoesTableExistSql() { } - protected override string GetInsertJournalEntrySql(string scriptName, string applied) { } - protected override string GetJournalEntriesSql() { } - } -} -namespace DbUp.SQLite.Helpers -{ - public class InMemorySQLiteDatabase : System.IDisposable - { - public InMemorySQLiteDatabase() { } - public string ConnectionString { get; set; } - public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } - public void Dispose() { } - public DbUp.Engine.Transactions.IConnectionManager GetConnectionManager() { } - } - public class SharedConnection : System.Data.IDbConnection, System.IDisposable - { - public SharedConnection(System.Data.IDbConnection dbConnection) { } - public string ConnectionString { get; set; } - public int ConnectionTimeout { get; } - public string Database { get; } - public System.Data.ConnectionState State { get; } - public System.Data.IDbTransaction BeginTransaction() { } - public System.Data.IDbTransaction BeginTransaction(System.Data.IsolationLevel il) { } - public void ChangeDatabase(string databaseName) { } - public void Close() { } - public System.Data.IDbCommand CreateCommand() { } - public void Dispose() { } - public void DoClose() { } - public void Open() { } - } - public class TemporarySQLiteDatabase : System.IDisposable - { - public TemporarySQLiteDatabase(string name) { } - public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } - public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } - public void Create() { } - public void Dispose() { } - } -} diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs similarity index 99% rename from src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs rename to src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index 15ac3ed..b691b30 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -71,7 +71,6 @@ public class TemporarySQLiteDatabase : System.IDisposable public TemporarySQLiteDatabase(string name) { } public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } - public void Create() { } public void Dispose() { } } } diff --git a/src/Tests/SQLiteSupportTests.cs b/src/Tests/SQLiteSupportTests.cs index bd0d553..0b32f7d 100644 --- a/src/Tests/SQLiteSupportTests.cs +++ b/src/Tests/SQLiteSupportTests.cs @@ -1,7 +1,5 @@ -#if !NETCORE -using System; -using System.Data.SQLite; -using System.IO; +using Microsoft.Data.Sqlite; +using Shouldly; using Xunit; namespace DbUp.SQLite.Tests @@ -13,18 +11,17 @@ public class SQLiteSupportTests [Fact] public void CanUseSQLite() { - var connectionString = string.Format("Data Source={0}; Version=3;", dbFilePath); - - if (!File.Exists(dbFilePath)) - { - SQLiteConnection.CreateFile(dbFilePath); - } + var connectionString = $"Data Source={dbFilePath}"; var upgrader = DeployChanges.To .SQLiteDatabase(connectionString) .WithScript("Script0001", "CREATE TABLE IF NOT EXISTS Foo (Id int)") .Build(); + + var result = upgrader.PerformUpgrade(); + + result.Error.ShouldBe(null); + result.Successful.ShouldBe(true); } } } -#endif diff --git a/src/Tests/SQLiteTableJournalTests.cs b/src/Tests/SQLiteTableJournalTests.cs index ce0171a..151aed8 100644 --- a/src/Tests/SQLiteTableJournalTests.cs +++ b/src/Tests/SQLiteTableJournalTests.cs @@ -1,11 +1,9 @@ -#if !NETCORE -using System.Collections.Generic; -using System.Data; -using System.Data.SQLite; +using System.Data; using DbUp.Engine; using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.Tests.Common; +using Microsoft.Data.Sqlite; using NSubstitute; using Shouldly; using Xunit; @@ -22,7 +20,7 @@ public void dbversion_is_zero_when_journal_table_not_exist() var command = Substitute.For(); dbConnection.CreateCommand().Returns(command); var connectionManager = Substitute.For(); - command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); }); + command.ExecuteScalar().Returns(x => { throw new SqliteException("table not found", 0); }); var consoleUpgradeLog = new ConsoleUpgradeLog(); var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); @@ -62,4 +60,3 @@ public void creates_a_new_journal_table_when_not_exist() } } } -#endif diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 3a39421..219abda 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -1,23 +1,19 @@ - net462;net8 + net8 Tests DbUp.SQLite.Tests - + enable enable - - $(DefineConstants);NETCORE - - - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/dbup-sqlite.sln.DotSettings b/src/dbup-sqlite.sln.DotSettings index 2c78c0a..d3334fb 100644 --- a/src/dbup-sqlite.sln.DotSettings +++ b/src/dbup-sqlite.sln.DotSettings @@ -5,5 +5,8 @@ SQ <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> + <Policy><Descriptor Staticness="Instance" AccessRightKinds="Private" Description="Instance fields (private)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static fields (private)"><ElementKinds><Kind Name="FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></Policy> + True <data><IncludeFilters /><ExcludeFilters /></data> <data /> \ No newline at end of file diff --git a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs index 16bec7b..8e3dfb3 100644 --- a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs @@ -1,17 +1,8 @@ using System; using DbUp.Engine.Transactions; using DbUp.Helpers; +using Microsoft.Data.Sqlite; -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Mono.Data.Sqlite.SqliteConnectionStringBuilder; -using SQLiteJournalModeEnum = Mono.Data.Sqlite.SQLiteJournalModeEnum; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Microsoft.Data.Sqlite.SqliteConnectionStringBuilder; -#else -using System.Data.SQLite; -#endif namespace DbUp.SQLite.Helpers { @@ -21,31 +12,22 @@ namespace DbUp.SQLite.Helpers public class InMemorySQLiteDatabase : IDisposable { readonly SQLiteConnectionManager connectionManager; - readonly SQLiteConnection sharedConnection; + readonly SqliteConnection sharedConnection; /// /// Initializes a new instance of the class. /// public InMemorySQLiteDatabase() { - var connectionStringBuilder = new SQLiteConnectionStringBuilder + var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:", -#if !NETCORE - Version = 3, DefaultTimeout = 5, -#if MONO - JournalMode = SQLiteJournalModeEnum.Off, -#else - JournalMode = SQLiteJournalModeEnum.Memory, -#endif - UseUTF16Encoding = true -#endif }; ConnectionString = connectionStringBuilder.ToString(); connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString); - sharedConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); + sharedConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sharedConnection.Open(); SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); } diff --git a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs index e1d1911..80cbac3 100644 --- a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs @@ -1,17 +1,8 @@ using System; using System.IO; using DbUp.Helpers; +using Microsoft.Data.Sqlite; -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Mono.Data.Sqlite.SqliteConnectionStringBuilder; -using SQLiteJournalModeEnum = Mono.Data.Sqlite.SQLiteJournalModeEnum; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -using SQLiteConnectionStringBuilder = Microsoft.Data.Sqlite.SqliteConnectionStringBuilder; -#else -using System.Data.SQLite; -#endif namespace DbUp.SQLite.Helpers { @@ -21,7 +12,7 @@ namespace DbUp.SQLite.Helpers public class TemporarySQLiteDatabase : IDisposable { readonly string dataSourcePath; - readonly SQLiteConnection sqLiteConnection; + readonly SqliteConnection sqLiteConnection; /// /// Initializes a new instance of the class. @@ -31,22 +22,13 @@ public TemporarySQLiteDatabase(string name) { dataSourcePath = Path.Combine(Directory.GetCurrentDirectory(), name); - var connectionStringBuilder = new SQLiteConnectionStringBuilder + var connectionStringBuilder = new SqliteConnectionStringBuilder { DataSource = name, -#if !NETCORE - Version = 3, DefaultTimeout = 5, -#if MONO - JournalMode = SQLiteJournalModeEnum.Off, -#else - JournalMode = SQLiteJournalModeEnum.Memory, -#endif - UseUTF16Encoding = true -#endif }; - sqLiteConnection = new SQLiteConnection(connectionStringBuilder.ConnectionString); + sqLiteConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sqLiteConnection.Open(); SharedConnection = new SharedConnection(sqLiteConnection); SqlRunner = new AdHocSqlRunner(() => sqLiteConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); @@ -59,20 +41,6 @@ public TemporarySQLiteDatabase(string name) public SharedConnection SharedConnection { get; } - /// - /// Creates the database. - /// - public void Create() - { -#if !NETCORE - var filePath = new FileInfo(dataSourcePath); - if (!filePath.Exists) - { - SQLiteConnection.CreateFile(dataSourcePath); - } -#endif - } - /// /// Deletes the database. /// @@ -82,14 +50,11 @@ public void Dispose() if (!filePath.Exists) return; SharedConnection.Dispose(); sqLiteConnection.Dispose(); -#if !NETCORE - SQLiteConnection.ClearAllPools(); - + // SQLite requires all created sql connection/command objects to be disposed // in order to delete the database file - GC.Collect(2, GCCollectionMode.Forced); - System.Threading.Thread.Sleep(100); -#endif + SqliteConnection.ClearAllPools(); + File.Delete(dataSourcePath); } } diff --git a/src/dbup-sqlite/SQLiteConnectionManager.cs b/src/dbup-sqlite/SQLiteConnectionManager.cs index 29f6edc..133ec6e 100644 --- a/src/dbup-sqlite/SQLiteConnectionManager.cs +++ b/src/dbup-sqlite/SQLiteConnectionManager.cs @@ -3,13 +3,7 @@ using System.Text.RegularExpressions; using DbUp.Engine.Transactions; using DbUp.SQLite.Helpers; -#if MONO -using SQLiteConnection = Mono.Data.Sqlite.SqliteConnection; -#elif NETCORE -using SQLiteConnection = Microsoft.Data.Sqlite.SqliteConnection; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite { @@ -21,7 +15,7 @@ public class SQLiteConnectionManager : DatabaseConnectionManager /// /// Creates new SQLite Connection Manager /// - public SQLiteConnectionManager(string connectionString) : base(l => new SQLiteConnection(connectionString)) + public SQLiteConnectionManager(string connectionString) : base(l => new SqliteConnection(connectionString)) { } @@ -46,4 +40,4 @@ public override IEnumerable SplitScriptIntoCommands(string scriptContent return scriptStatements; } } -} \ No newline at end of file +} diff --git a/src/dbup-sqlite/SQLiteScriptExecutor.cs b/src/dbup-sqlite/SQLiteScriptExecutor.cs index 741b52f..d966615 100644 --- a/src/dbup-sqlite/SQLiteScriptExecutor.cs +++ b/src/dbup-sqlite/SQLiteScriptExecutor.cs @@ -4,14 +4,7 @@ using DbUp.Engine.Output; using DbUp.Engine.Transactions; using DbUp.Support; - -#if MONO -using SQLiteException = Mono.Data.Sqlite.SqliteException; -#elif NETCORE -using SQLiteException = Microsoft.Data.Sqlite.SqliteException; -#else -using System.Data.SQLite; -#endif +using Microsoft.Data.Sqlite; namespace DbUp.SQLite { @@ -46,15 +39,11 @@ protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScri { executeCommand(); } - catch (SQLiteException exception) + catch (SqliteException exception) { - Log().WriteInformation("SQLite exception has occurred in script: '{0}'", script.Name); -#if NETCORE - Log().WriteError("Script block number: {0}; Error Code: {1}; Message: {2}", index, exception.SqliteErrorCode, exception.Message); -#else - Log().WriteError("Script block number: {0}; Error Code: {1}; Message: {2}", index, exception.ErrorCode, exception.Message); -#endif - Log().WriteError(exception.ToString()); + Log().LogInformation("SQLite exception has occurred in script: '{0}'", script.Name); + Log().LogError("Script block number: {0}; Error Code: {1}; Message: {2}", index, exception.SqliteErrorCode, exception.Message); + Log().LogError(exception.ToString()); throw; } } diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index da35aad..9215449 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -6,7 +6,7 @@ DbUp Contributors DbUp Copyright © DbUp Contributors 2015 - netstandard1.3;net462 + netstandard2.0 dbup-sqlite DbUp.SQLite dbup-sqlite @@ -16,22 +16,15 @@ dbup-icon.png - - $(DefineConstants);NETCORE + + true + true + embedded - - - - - - - - - - - + + From 3077cb2c8ad342d12125b72172df11f4d225cd50 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Fri, 26 Jul 2024 09:21:28 +1000 Subject: [PATCH 4/9] Bump to the next beta --- src/Tests/Tests.csproj | 2 +- src/dbup-sqlite/dbup-sqlite.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 219abda..137ec2f 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -10,7 +10,7 @@ - + diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index 9215449..8ad197e 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -23,7 +23,7 @@ - + From 0cd4c56f13969a91e80597f2df02ca3fee560f36 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 29 Jul 2024 16:37:11 +1000 Subject: [PATCH 5/9] Added link to the Issue --- src/Tests/SQLiteSupportTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Tests/SQLiteSupportTests.cs b/src/Tests/SQLiteSupportTests.cs index 5174ffb..c861ec1 100644 --- a/src/Tests/SQLiteSupportTests.cs +++ b/src/Tests/SQLiteSupportTests.cs @@ -23,8 +23,11 @@ public void CanUseSQLite() result.Successful.ShouldBe(true); } + /// + /// Test for https://github.com/DbUp/dbup-sqlite/issues/2 + /// [Fact] - public void DoesNotExhibitSafeHandleError_Issue577() + public void DoesNotExhibitSafeHandleError() { var connectionString = "Data source=:memory:"; From 025c940a173438e98e9ec74c14c135008ffd0780 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Mon, 29 Jul 2024 17:09:19 +1000 Subject: [PATCH 6/9] Removed PRAGMA because it doesn't work in this version --- src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs index c58e744..2985b19 100644 --- a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs @@ -23,8 +23,7 @@ public InMemorySQLiteDatabase() { DataSource = ":memory:", DefaultTimeout = 5, - Mode = SqliteOpenMode.Memory, - ConnectionString = "PRAGMA encoding='UTF-16'; PRAGMA journal_mode='MEMORY';" + Mode = SqliteOpenMode.Memory }; ConnectionString = connectionStringBuilder.ToString(); From 73dd9a9010ab446a6aa27ace5f62fb7c06b80640 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 17 Dec 2024 10:32:44 +1000 Subject: [PATCH 7/9] Referenced the `Microsoft.Data.Sqlite.Core` package (#11) --- src/Sample/Sample.csproj | 1 + src/Tests/Tests.csproj | 1 + src/dbup-sqlite/dbup-sqlite.csproj | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj index ad8a65c..238a0ef 100644 --- a/src/Sample/Sample.csproj +++ b/src/Sample/Sample.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 137ec2f..337d96d 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -10,6 +10,7 @@ + diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index 8ad197e..9455962 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -24,7 +24,7 @@ - + From 77fae40811297d104c37e963d6ecc37f04df0d0b Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 17 Dec 2024 10:37:02 +1000 Subject: [PATCH 8/9] Changed case from `SQLite` to `Sqlite` (#12) * Changed case from `SQLite` to `Sqlite` https://github.com/DbUp/dbup-sqlite/issues/6 * Fix up casing in test --- src/Sample/Program.cs | 14 +++--- .../NoPublicApiChanges.Run.approved.cs | 44 +++++++++---------- src/Tests/DatabaseSupportTests.cs | 6 +-- src/Tests/NoPublicApiChanges.cs | 4 +- ...eSupportTests.cs => SqliteSupportTests.cs} | 10 ++--- ...nalTests.cs => SqliteTableJournalTests.cs} | 8 ++-- src/Tests/Tests.csproj | 2 +- ...eDatabase.cs => InMemorySqliteDatabase.cs} | 14 +++--- src/dbup-sqlite/Helpers/SharedConnection.cs | 2 +- ...Database.cs => TemporarySqliteDatabase.cs} | 10 ++--- ...nManager.cs => SqliteConnectionManager.cs} | 10 ++--- src/dbup-sqlite/SqliteExtensions.cs | 30 ++++++------- ...eObjectParser.cs => SqliteObjectParser.cs} | 6 +-- src/dbup-sqlite/SqlitePreprocessor.cs | 4 +- ...iptExecutor.cs => SqliteScriptExecutor.cs} | 10 ++--- ...eTableJournal.cs => SqliteTableJournal.cs} | 10 ++--- src/dbup-sqlite/dbup-sqlite.csproj | 2 +- 17 files changed, 93 insertions(+), 93 deletions(-) rename src/Tests/{SQLiteSupportTests.cs => SqliteSupportTests.cs} (85%) rename src/Tests/{SQLiteTableJournalTests.cs => SqliteTableJournalTests.cs} (91%) rename src/dbup-sqlite/Helpers/{InMemorySQLiteDatabase.cs => InMemorySqliteDatabase.cs} (81%) rename src/dbup-sqlite/Helpers/{TemporarySQLiteDatabase.cs => TemporarySqliteDatabase.cs} (88%) rename src/dbup-sqlite/{SQLiteConnectionManager.cs => SqliteConnectionManager.cs} (82%) rename src/dbup-sqlite/{SQLiteObjectParser.cs => SqliteObjectParser.cs} (62%) rename src/dbup-sqlite/{SQLiteScriptExecutor.cs => SqliteScriptExecutor.cs} (87%) rename src/dbup-sqlite/{SQLiteTableJournal.cs => SqliteTableJournal.cs} (84%) diff --git a/src/Sample/Program.cs b/src/Sample/Program.cs index 86cd598..abc1013 100644 --- a/src/Sample/Program.cs +++ b/src/Sample/Program.cs @@ -1,7 +1,7 @@ using System; using Microsoft.Data.Sqlite; -namespace SQLiteSampleApplication +namespace SqliteSampleApplication { public static class Program { @@ -14,11 +14,11 @@ static void Main() static void InMemoryDb() { - using (var database = new DbUp.SQLite.Helpers.InMemorySQLiteDatabase()) + using (var database = new DbUp.Sqlite.Helpers.InMemorySqliteDatabase()) { var upgrader = DbUp.DeployChanges.To - .SQLiteDatabase(database.ConnectionString) + .SqliteDatabase(database.ConnectionString) .WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); @@ -35,11 +35,11 @@ static void InMemoryDb() static void TemporaryFileDb() { - using (var database = new DbUp.SQLite.Helpers.TemporarySQLiteDatabase("test.db")) + using (var database = new DbUp.Sqlite.Helpers.TemporarySqliteDatabase("test.db")) { var upgrader = DbUp.DeployChanges.To - .SQLiteDatabase(database.SharedConnection) + .SqliteDatabase(database.SharedConnection) .WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); @@ -58,11 +58,11 @@ static void PermanentFileDb() { SqliteConnection connection = new("Data Source=dbup.db"); - using (var database = new DbUp.SQLite.Helpers.SharedConnection(connection)) + using (var database = new DbUp.Sqlite.Helpers.SharedConnection(connection)) { var upgrader = DbUp.DeployChanges .To - .SQLiteDatabase(connection.ConnectionString) + .SqliteDatabase(connection.ConnectionString) .WithScriptsEmbeddedInAssembly(System.Reflection.Assembly.GetExecutingAssembly()) .LogToConsole() .Build(); diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index b691b30..5d983b2 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -2,49 +2,49 @@ [assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] [assembly: System.Runtime.InteropServices.GuidAttribute("9f949414-f078-49bf-b50e-a3859c18fb6e")] -public static class SQLiteExtensions +public static class SqliteExtensions { - public static DbUp.Builder.UpgradeEngineBuilder JournalToSQLiteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { } - public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } + public static DbUp.Builder.UpgradeEngineBuilder JournalToSqliteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { } + public static DbUp.Builder.UpgradeEngineBuilder SqliteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } + public static DbUp.Builder.UpgradeEngineBuilder SqliteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Sqlite.Helpers.SharedConnection sharedConnection) { } } -namespace DbUp.SQLite +namespace DbUp.Sqlite { - public class SQLiteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager + public class SqliteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager { - public SQLiteConnectionManager(string connectionString) { } - public SQLiteConnectionManager(DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } + public SqliteConnectionManager(string connectionString) { } + public SqliteConnectionManager(DbUp.Sqlite.Helpers.SharedConnection sharedConnection) { } public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } } - public class SQLiteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser + public class SqliteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser { - public SQLiteObjectParser() { } + public SqliteObjectParser() { } } - public class SQLitePreprocessor : DbUp.Engine.IScriptPreprocessor + public class SqlitePreprocessor : DbUp.Engine.IScriptPreprocessor { - public SQLitePreprocessor() { } + public SqlitePreprocessor() { } public string Process(string contents) { } } - public class SQLiteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor + public class SqliteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor { - public SQLiteScriptExecutor(System.Func connectionManagerFactory, System.Func log, string schema, System.Func variablesEnabled, System.Collections.Generic.IEnumerable scriptPreprocessors, System.Func journalFactory) { } + public SqliteScriptExecutor(System.Func connectionManagerFactory, System.Func log, string schema, System.Func variablesEnabled, System.Collections.Generic.IEnumerable scriptPreprocessors, System.Func journalFactory) { } protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { } protected override string GetVerifySchemaSql(string schema) { } } - public class SQLiteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal + public class SqliteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal { - public SQLiteTableJournal(System.Func connectionManager, System.Func logger, string table) { } + public SqliteTableJournal(System.Func connectionManager, System.Func logger, string table) { } protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { } protected override string DoesTableExistSql() { } protected override string GetInsertJournalEntrySql(string scriptName, string applied) { } protected override string GetJournalEntriesSql() { } } } -namespace DbUp.SQLite.Helpers +namespace DbUp.Sqlite.Helpers { - public class InMemorySQLiteDatabase : System.IDisposable + public class InMemorySqliteDatabase : System.IDisposable { - public InMemorySQLiteDatabase() { } + public InMemorySqliteDatabase() { } public string ConnectionString { get; set; } public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } public void Dispose() { } @@ -66,10 +66,10 @@ public void Dispose() { } public void DoClose() { } public void Open() { } } - public class TemporarySQLiteDatabase : System.IDisposable + public class TemporarySqliteDatabase : System.IDisposable { - public TemporarySQLiteDatabase(string name) { } - public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } + public TemporarySqliteDatabase(string name) { } + public DbUp.Sqlite.Helpers.SharedConnection SharedConnection { get; } public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } public void Dispose() { } } diff --git a/src/Tests/DatabaseSupportTests.cs b/src/Tests/DatabaseSupportTests.cs index 6fd3237..f56b0c5 100644 --- a/src/Tests/DatabaseSupportTests.cs +++ b/src/Tests/DatabaseSupportTests.cs @@ -1,7 +1,7 @@ using DbUp.Builder; using DbUp.Tests.Common; -namespace DbUp.SQLite.Tests; +namespace DbUp.Sqlite.Tests; public class DatabaseSupportTests : DatabaseSupportTestsBase { @@ -10,11 +10,11 @@ public DatabaseSupportTests() : base() } protected override UpgradeEngineBuilder DeployTo(SupportedDatabases to) - => to.SQLiteDatabase(""); + => to.SqliteDatabase(""); protected override UpgradeEngineBuilder AddCustomNamedJournalToBuilder(UpgradeEngineBuilder builder, string schema, string tableName) => builder.JournalTo( (connectionManagerFactory, logFactory) - => new SQLiteTableJournal(connectionManagerFactory, logFactory, tableName) + => new SqliteTableJournal(connectionManagerFactory, logFactory, tableName) ); } diff --git a/src/Tests/NoPublicApiChanges.cs b/src/Tests/NoPublicApiChanges.cs index 81e81d9..7d86fb2 100644 --- a/src/Tests/NoPublicApiChanges.cs +++ b/src/Tests/NoPublicApiChanges.cs @@ -1,11 +1,11 @@ using DbUp.Tests.Common; -namespace DbUp.SQLite.Tests; +namespace DbUp.Sqlite.Tests; public class NoPublicApiChanges : NoPublicApiChangesBase { public NoPublicApiChanges() - : base(typeof(SQLiteExtensions).Assembly) + : base(typeof(SqliteExtensions).Assembly) { } } diff --git a/src/Tests/SQLiteSupportTests.cs b/src/Tests/SqliteSupportTests.cs similarity index 85% rename from src/Tests/SQLiteSupportTests.cs rename to src/Tests/SqliteSupportTests.cs index c861ec1..4a4c2c1 100644 --- a/src/Tests/SQLiteSupportTests.cs +++ b/src/Tests/SqliteSupportTests.cs @@ -1,19 +1,19 @@ using Shouldly; using Xunit; -namespace DbUp.SQLite.Tests +namespace DbUp.Sqlite.Tests { - public class SQLiteSupportTests + public class SqliteSupportTests { static readonly string DbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db"); [Fact] - public void CanUseSQLite() + public void CanUseSqlite() { var connectionString = $"Data Source={DbFilePath}"; var upgrader = DeployChanges.To - .SQLiteDatabase(connectionString) + .SqliteDatabase(connectionString) .WithScript("Script0001", "CREATE TABLE IF NOT EXISTS Foo (Id int)") .Build(); @@ -33,7 +33,7 @@ public void DoesNotExhibitSafeHandleError() var upgrader = DeployChanges.To - .SQLiteDatabase(connectionString) + .SqliteDatabase(connectionString) .WithScript("Script001", @" create table test ( contact_id INTEGER PRIMARY KEY diff --git a/src/Tests/SQLiteTableJournalTests.cs b/src/Tests/SqliteTableJournalTests.cs similarity index 91% rename from src/Tests/SQLiteTableJournalTests.cs rename to src/Tests/SqliteTableJournalTests.cs index 151aed8..cdf7c59 100644 --- a/src/Tests/SQLiteTableJournalTests.cs +++ b/src/Tests/SqliteTableJournalTests.cs @@ -8,9 +8,9 @@ using Shouldly; using Xunit; -namespace DbUp.SQLite.Tests +namespace DbUp.Sqlite.Tests { - public class SQLiteTableJournalTests + public class SqliteTableJournalTests { [Fact] public void dbversion_is_zero_when_journal_table_not_exist() @@ -22,7 +22,7 @@ public void dbversion_is_zero_when_journal_table_not_exist() var connectionManager = Substitute.For(); command.ExecuteScalar().Returns(x => { throw new SqliteException("table not found", 0); }); var consoleUpgradeLog = new ConsoleUpgradeLog(); - var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); + var journal = new SqliteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); // When var scripts = journal.GetExecutedScripts(); @@ -47,7 +47,7 @@ public void creates_a_new_journal_table_when_not_exist() command.CreateParameter().Returns(param1, param2); command.ExecuteScalar().Returns(x => 0); var consoleUpgradeLog = new ConsoleUpgradeLog(); - var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); + var journal = new SqliteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); // When journal.StoreExecutedScript(new SqlScript("test", "select 1"), () => command); diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 337d96d..fde43b2 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -3,7 +3,7 @@ net8 Tests - DbUp.SQLite.Tests + DbUp.Sqlite.Tests enable enable diff --git a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/InMemorySqliteDatabase.cs similarity index 81% rename from src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs rename to src/dbup-sqlite/Helpers/InMemorySqliteDatabase.cs index 2985b19..d4a3a38 100644 --- a/src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/InMemorySqliteDatabase.cs @@ -4,20 +4,20 @@ using Microsoft.Data.Sqlite; -namespace DbUp.SQLite.Helpers +namespace DbUp.Sqlite.Helpers { /// /// Used to create in-memory SQLite database that is deleted at the end of a test. /// - public class InMemorySQLiteDatabase : IDisposable + public class InMemorySqliteDatabase : IDisposable { - readonly SQLiteConnectionManager connectionManager; + readonly SqliteConnectionManager connectionManager; readonly SqliteConnection sharedConnection; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public InMemorySQLiteDatabase() + public InMemorySqliteDatabase() { var connectionStringBuilder = new SqliteConnectionStringBuilder { @@ -27,10 +27,10 @@ public InMemorySQLiteDatabase() }; ConnectionString = connectionStringBuilder.ToString(); - connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString); + connectionManager = new SqliteConnectionManager(connectionStringBuilder.ConnectionString); sharedConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sharedConnection.Open(); - SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); + SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SqliteObjectParser(), null, () => true); } public string ConnectionString { get; set; } diff --git a/src/dbup-sqlite/Helpers/SharedConnection.cs b/src/dbup-sqlite/Helpers/SharedConnection.cs index 823996c..3540479 100644 --- a/src/dbup-sqlite/Helpers/SharedConnection.cs +++ b/src/dbup-sqlite/Helpers/SharedConnection.cs @@ -1,7 +1,7 @@ using System; using System.Data; -namespace DbUp.SQLite.Helpers +namespace DbUp.Sqlite.Helpers { /// /// A database connection wrapper to manage underlying connection as a shared connection diff --git a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs b/src/dbup-sqlite/Helpers/TemporarySqliteDatabase.cs similarity index 88% rename from src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs rename to src/dbup-sqlite/Helpers/TemporarySqliteDatabase.cs index 80cbac3..2626f03 100644 --- a/src/dbup-sqlite/Helpers/TemporarySQLiteDatabase.cs +++ b/src/dbup-sqlite/Helpers/TemporarySqliteDatabase.cs @@ -4,21 +4,21 @@ using Microsoft.Data.Sqlite; -namespace DbUp.SQLite.Helpers +namespace DbUp.Sqlite.Helpers { /// /// Used to create SQLite databases that are deleted at the end of a test. /// - public class TemporarySQLiteDatabase : IDisposable + public class TemporarySqliteDatabase : IDisposable { readonly string dataSourcePath; readonly SqliteConnection sqLiteConnection; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The name. - public TemporarySQLiteDatabase(string name) + public TemporarySqliteDatabase(string name) { dataSourcePath = Path.Combine(Directory.GetCurrentDirectory(), name); @@ -31,7 +31,7 @@ public TemporarySQLiteDatabase(string name) sqLiteConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); sqLiteConnection.Open(); SharedConnection = new SharedConnection(sqLiteConnection); - SqlRunner = new AdHocSqlRunner(() => sqLiteConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); + SqlRunner = new AdHocSqlRunner(() => sqLiteConnection.CreateCommand(), new SqliteObjectParser(), null, () => true); } /// diff --git a/src/dbup-sqlite/SQLiteConnectionManager.cs b/src/dbup-sqlite/SqliteConnectionManager.cs similarity index 82% rename from src/dbup-sqlite/SQLiteConnectionManager.cs rename to src/dbup-sqlite/SqliteConnectionManager.cs index 133ec6e..af3191b 100644 --- a/src/dbup-sqlite/SQLiteConnectionManager.cs +++ b/src/dbup-sqlite/SqliteConnectionManager.cs @@ -2,27 +2,27 @@ using System.Linq; using System.Text.RegularExpressions; using DbUp.Engine.Transactions; -using DbUp.SQLite.Helpers; +using DbUp.Sqlite.Helpers; using Microsoft.Data.Sqlite; -namespace DbUp.SQLite +namespace DbUp.Sqlite { /// /// Connection manager for Sql Lite /// - public class SQLiteConnectionManager : DatabaseConnectionManager + public class SqliteConnectionManager : DatabaseConnectionManager { /// /// Creates new SQLite Connection Manager /// - public SQLiteConnectionManager(string connectionString) : base(l => new SqliteConnection(connectionString)) + public SqliteConnectionManager(string connectionString) : base(l => new SqliteConnection(connectionString)) { } /// /// Creates new SQLite Connection Manager /// - public SQLiteConnectionManager(SharedConnection sharedConnection) : base(l => sharedConnection) + public SqliteConnectionManager(SharedConnection sharedConnection) : base(l => sharedConnection) { } diff --git a/src/dbup-sqlite/SqliteExtensions.cs b/src/dbup-sqlite/SqliteExtensions.cs index b72c0f8..7c35462 100644 --- a/src/dbup-sqlite/SqliteExtensions.cs +++ b/src/dbup-sqlite/SqliteExtensions.cs @@ -1,6 +1,6 @@ using DbUp.Builder; -using DbUp.SQLite; -using DbUp.SQLite.Helpers; +using DbUp.Sqlite; +using DbUp.Sqlite.Helpers; /// /// Configuration extension methods for SQLite (see http://www.sqlite.org/) @@ -9,7 +9,7 @@ // Since the class just contains extension methods, we leave it in the root so that it is always discovered // and people don't have to manually add using statements. // ReSharper disable CheckNamespace -public static class SQLiteExtensions +public static class SqliteExtensions // ReSharper restore CheckNamespace { /// @@ -20,14 +20,14 @@ public static class SQLiteExtensions /// /// A builder for a database upgrader designed for SQLite databases. /// - public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases supported, string connectionString) + public static UpgradeEngineBuilder SqliteDatabase(this SupportedDatabases supported, string connectionString) { var builder = new UpgradeEngineBuilder(); - builder.Configure(c => c.ConnectionManager = new SQLiteConnectionManager(connectionString)); - builder.Configure(c => c.Journal = new SQLiteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions")); - builder.Configure(c => c.ScriptExecutor = new SQLiteScriptExecutor(() => c.ConnectionManager, () => c.Log, null, + builder.Configure(c => c.ConnectionManager = new SqliteConnectionManager(connectionString)); + builder.Configure(c => c.Journal = new SqliteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions")); + builder.Configure(c => c.ScriptExecutor = new SqliteScriptExecutor(() => c.ConnectionManager, () => c.Log, null, () => c.VariablesEnabled, c.ScriptPreprocessors, () => c.Journal)); - builder.WithPreprocessor(new SQLitePreprocessor()); + builder.WithPreprocessor(new SqlitePreprocessor()); return builder; } @@ -39,14 +39,14 @@ public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases suppor /// /// A builder for a database upgrader designed for SQLite databases. /// - public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases supported, SharedConnection sharedConnection) + public static UpgradeEngineBuilder SqliteDatabase(this SupportedDatabases supported, SharedConnection sharedConnection) { var builder = new UpgradeEngineBuilder(); - builder.Configure(c => c.ConnectionManager = new SQLiteConnectionManager(sharedConnection)); - builder.Configure(c => c.Journal = new SQLiteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions")); - builder.Configure(c => c.ScriptExecutor = new SQLiteScriptExecutor(() => c.ConnectionManager, () => c.Log, null, + builder.Configure(c => c.ConnectionManager = new SqliteConnectionManager(sharedConnection)); + builder.Configure(c => c.Journal = new SqliteTableJournal(() => c.ConnectionManager, () => c.Log, "SchemaVersions")); + builder.Configure(c => c.ScriptExecutor = new SqliteScriptExecutor(() => c.ConnectionManager, () => c.Log, null, () => c.VariablesEnabled, c.ScriptPreprocessors, () => c.Journal)); - builder.WithPreprocessor(new SQLitePreprocessor()); + builder.WithPreprocessor(new SqlitePreprocessor()); return builder; } @@ -55,9 +55,9 @@ public static UpgradeEngineBuilder SQLiteDatabase(this SupportedDatabases suppor /// /// The name of the table used to store the list of executed scripts. /// The used to set the journal table name. - public static UpgradeEngineBuilder JournalToSQLiteTable(this UpgradeEngineBuilder builder, string table) + public static UpgradeEngineBuilder JournalToSqliteTable(this UpgradeEngineBuilder builder, string table) { - builder.Configure(c => c.Journal = new SQLiteTableJournal(() => c.ConnectionManager, () => c.Log, table)); + builder.Configure(c => c.Journal = new SqliteTableJournal(() => c.ConnectionManager, () => c.Log, table)); return builder; } } diff --git a/src/dbup-sqlite/SQLiteObjectParser.cs b/src/dbup-sqlite/SqliteObjectParser.cs similarity index 62% rename from src/dbup-sqlite/SQLiteObjectParser.cs rename to src/dbup-sqlite/SqliteObjectParser.cs index 71d6320..2d674d6 100644 --- a/src/dbup-sqlite/SQLiteObjectParser.cs +++ b/src/dbup-sqlite/SqliteObjectParser.cs @@ -1,13 +1,13 @@ using DbUp.Support; -namespace DbUp.SQLite +namespace DbUp.Sqlite { /// /// Parses Sql Objects and performs quoting functions. /// - public class SQLiteObjectParser : SqlObjectParser + public class SqliteObjectParser : SqlObjectParser { - public SQLiteObjectParser() + public SqliteObjectParser() : base("[", "]") { } diff --git a/src/dbup-sqlite/SqlitePreprocessor.cs b/src/dbup-sqlite/SqlitePreprocessor.cs index 7efb51f..6cbd668 100644 --- a/src/dbup-sqlite/SqlitePreprocessor.cs +++ b/src/dbup-sqlite/SqlitePreprocessor.cs @@ -1,12 +1,12 @@ using System.Text.RegularExpressions; using DbUp.Engine; -namespace DbUp.SQLite +namespace DbUp.Sqlite { /// /// This preprocessor makes adjustments to your sql to make it compatible with Sqlite /// - public class SQLitePreprocessor : IScriptPreprocessor + public class SqlitePreprocessor : IScriptPreprocessor { /// /// Performs some preprocessing step on a SQLite script diff --git a/src/dbup-sqlite/SQLiteScriptExecutor.cs b/src/dbup-sqlite/SqliteScriptExecutor.cs similarity index 87% rename from src/dbup-sqlite/SQLiteScriptExecutor.cs rename to src/dbup-sqlite/SqliteScriptExecutor.cs index d966615..9b0ed03 100644 --- a/src/dbup-sqlite/SQLiteScriptExecutor.cs +++ b/src/dbup-sqlite/SqliteScriptExecutor.cs @@ -6,15 +6,15 @@ using DbUp.Support; using Microsoft.Data.Sqlite; -namespace DbUp.SQLite +namespace DbUp.Sqlite { /// /// An implementation of that executes against a SQLite database. /// - public class SQLiteScriptExecutor : ScriptExecutor + public class SqliteScriptExecutor : ScriptExecutor { /// - /// Initializes an instance of the class. + /// Initializes an instance of the class. /// /// /// The logging mechanism. @@ -22,9 +22,9 @@ public class SQLiteScriptExecutor : ScriptExecutor /// Function that returns true if variables should be replaced, false otherwise. /// Script Preprocessors in addition to variable substitution /// Database journal - public SQLiteScriptExecutor(Func connectionManagerFactory, Func log, string schema, Func variablesEnabled, + public SqliteScriptExecutor(Func connectionManagerFactory, Func log, string schema, Func variablesEnabled, IEnumerable scriptPreprocessors, Func journalFactory) - : base(connectionManagerFactory, new SQLiteObjectParser(), log, schema, variablesEnabled, scriptPreprocessors, journalFactory) + : base(connectionManagerFactory, new SqliteObjectParser(), log, schema, variablesEnabled, scriptPreprocessors, journalFactory) { } diff --git a/src/dbup-sqlite/SQLiteTableJournal.cs b/src/dbup-sqlite/SqliteTableJournal.cs similarity index 84% rename from src/dbup-sqlite/SQLiteTableJournal.cs rename to src/dbup-sqlite/SqliteTableJournal.cs index a3a4714..92c6d23 100644 --- a/src/dbup-sqlite/SQLiteTableJournal.cs +++ b/src/dbup-sqlite/SqliteTableJournal.cs @@ -4,19 +4,19 @@ using DbUp.Engine.Transactions; using DbUp.Support; -namespace DbUp.SQLite +namespace DbUp.Sqlite { /// /// An implementation of the interface which tracks version numbers for a /// SQLite database using a table called SchemaVersions. /// - public class SQLiteTableJournal : TableJournal + public class SqliteTableJournal : TableJournal { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public SQLiteTableJournal(Func connectionManager, Func logger, string table) : - base(connectionManager, logger, new SQLiteObjectParser(), null, table) + public SqliteTableJournal(Func connectionManager, Func logger, string table) : + base(connectionManager, logger, new SqliteObjectParser(), null, table) { } protected override string GetInsertJournalEntrySql(string @scriptName, string @applied) diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index 9455962..6c54d7f 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -8,7 +8,7 @@ Copyright © DbUp Contributors 2015 netstandard2.0 dbup-sqlite - DbUp.SQLite + DbUp.Sqlite dbup-sqlite ../dbup.snk true From 17b8fd0769c090d2dd101f3dcd6ec29237cfaa36 Mon Sep 17 00:00:00 2001 From: Robert Wagner Date: Tue, 17 Dec 2024 10:40:34 +1000 Subject: [PATCH 9/9] Update all the references --- src/Sample/Sample.csproj | 2 +- src/Tests/Tests.csproj | 12 ++++++------ src/dbup-sqlite/dbup-sqlite.csproj | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Sample/Sample.csproj b/src/Sample/Sample.csproj index 238a0ef..06f1bce 100644 --- a/src/Sample/Sample.csproj +++ b/src/Sample/Sample.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index fde43b2..b87adaa 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -10,15 +10,15 @@ - - - - - + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/dbup-sqlite/dbup-sqlite.csproj b/src/dbup-sqlite/dbup-sqlite.csproj index 6c54d7f..8220aad 100644 --- a/src/dbup-sqlite/dbup-sqlite.csproj +++ b/src/dbup-sqlite/dbup-sqlite.csproj @@ -23,8 +23,8 @@ - - + +