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 diff --git a/src/Directory.Build.props b/src/Directory.Build.props index d4e6134..8ed21b4 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -10,18 +10,4 @@ latest true - - - - - true - - - true - - - embedded - - - diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt similarity index 94% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.approved.txt index a413139..c931df0 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 1 from user_tables where table_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 1 from user_tables where table_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 94% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.approved.txt index d7207b2..49d8aa4 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 1 from user_tables where table_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 1 from user_tables where table_name = 'TESTSCHEMAVERSIONS' DB Operation: Dispose command Info: Creating the "test"."TestSchemaVersions" table diff --git a/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt b/src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt similarity index 94% rename from src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt rename to src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.approved.txt index 842879b..2475c9c 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 1 from user_tables where table_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 1 from user_tables where table_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 043616c..0000000 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs +++ /dev/null @@ -1,80 +0,0 @@ -[assembly: System.CLSCompliantAttribute(true)] -[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] -[assembly: System.Runtime.InteropServices.GuidAttribute("4f62ae2f-797b-488d-a71e-f27873167fa1")] - -namespace DbUp.Oracle -{ - [System.ObsoleteAttribute()] - public class OracleCommandReader : DbUp.Support.SqlCommandReader, System.IDisposable - { - public OracleCommandReader(string sqlText) { } - protected override bool IsCustomStatement { get; } - protected override void ReadCustomStatement() { } - } - public class OracleCommandSplitter - { - [System.ObsoleteAttribute()] - public OracleCommandSplitter() { } - public OracleCommandSplitter(char delimiter) { } - public System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } - } - public class OracleConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager - { - [System.ObsoleteAttribute("Use OracleConnectionManager(string, OracleCommandSplitter) and supply an appropriate command splitter instance.")] - public OracleConnectionManager(string connectionString) { } - public OracleConnectionManager(string connectionString, DbUp.Oracle.OracleCommandSplitter commandSplitter) { } - public override System.Collections.Generic.IEnumerable SplitScriptIntoCommands(string scriptContents) { } - } - public class OracleCustomDelimiterCommandReader : DbUp.Support.SqlCommandReader, System.IDisposable - { - public OracleCustomDelimiterCommandReader(string sqlText, char delimiter) { } - protected override bool IsCustomStatement { get; } - protected override void ReadCustomStatement() { } - } - public static class OracleExtensions - { - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { } - [System.ObsoleteAttribute("Use OracleDatabaseWithDefaultDelimiter, OracleDatabaseWithSemicolonDelimiter or the OracleDatabase with the delimiter parameter instead, see https://github.com/DbUp/DbUp/pull/335")] - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, char delimiter) { } - [System.ObsoleteAttribute("Use the parameter that takes a delimiter instead, see https://github.com/DbUp/DbUp/pull/335")] - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, char delimiter) { } - [System.ObsoleteAttribute("Use OracleDatabaseWithDefaultDelimiter, OracleDatabaseWithSemicolonDelimiter or the OracleDatabase with the delimiter parameter instead, see https://github.com/DbUp/DbUp/pull/335")] - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema, string delimiter) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabaseWithDefaultDelimiter(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - public static DbUp.Builder.UpgradeEngineBuilder OracleDatabaseWithSemicolonDelimiter(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } - } - public class OracleObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser - { - public OracleObjectParser() { } - } - public class OraclePreprocessor : DbUp.Engine.IScriptPreprocessor - { - public OraclePreprocessor() { } - public string Process(string contents) { } - } - public class OracleScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor - { - public OracleScriptExecutor(System.Func connectionManagerFactory, System.Func log, string schema, System.Func variablesEnabled, System.Collections.Generic.IEnumerable scriptPreprocessors, System.Func journalFactory) { } - public override void Execute(DbUp.Engine.SqlScript script) { } - protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { } - protected override string GetVerifySchemaSql(string schema) { } - } - public class OracleTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal - { - public static System.Globalization.CultureInfo English; - public OracleTableJournal(System.Func connectionManager, System.Func logger, string schema, string table) { } - protected string CreateSchemaTableSequenceSql() { } - protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { } - protected string CreateSchemaTableTriggerSql() { } - protected override string DoesTableExistSql() { } - public override void EnsureTableExistsAndIsLatestVersion(System.Func dbCommandFactory) { } - protected System.Data.IDbCommand GetCreateTableSequence(System.Func dbCommandFactory) { } - protected System.Data.IDbCommand GetCreateTableTrigger(System.Func dbCommandFactory) { } - protected override string GetInsertJournalEntrySql(string scriptName, string applied) { } - protected override string GetJournalEntriesSql() { } - } -} diff --git a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs similarity index 97% rename from src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs rename to src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs index 043616c..ff5a8ff 100644 --- a/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs +++ b/src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs @@ -33,6 +33,7 @@ protected override void ReadCustomStatement() { } } public static class OracleExtensions { + public static DbUp.Builder.UpgradeEngineBuilder JournalToOracleTable(this DbUp.Builder.UpgradeEngineBuilder builder, string schema, string table) { } public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { } [System.ObsoleteAttribute("Use OracleDatabaseWithDefaultDelimiter, OracleDatabaseWithSemicolonDelimiter or the OracleDatabase with the delimiter parameter instead, see https://github.com/DbUp/DbUp/pull/335")] public static DbUp.Builder.UpgradeEngineBuilder OracleDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } diff --git a/src/Tests/Tests.csproj b/src/Tests/Tests.csproj index 353241d..770784d 100644 --- a/src/Tests/Tests.csproj +++ b/src/Tests/Tests.csproj @@ -1,19 +1,19 @@ - net462;net8 + net8 Tests DbUp.Oracle.Tests - + enable enable - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/dbup-oracle.sln b/src/dbup-oracle.sln index 7e604bc..e75dbed 100644 --- a/src/dbup-oracle.sln +++ b/src/dbup-oracle.sln @@ -23,6 +23,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{77157734-01D ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig dbup-oracle.sln.DotSettings = dbup-oracle.sln.DotSettings + Directory.Build.props = Directory.Build.props EndProjectSection EndProject Global diff --git a/src/dbup-oracle.sln.DotSettings b/src/dbup-oracle.sln.DotSettings index 2c78c0a..d3334fb 100644 --- a/src/dbup-oracle.sln.DotSettings +++ b/src/dbup-oracle.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-oracle/OracleCommandReader.cs b/src/dbup-oracle/OracleCommandReader.cs index ffa686c..41e2750 100644 --- a/src/dbup-oracle/OracleCommandReader.cs +++ b/src/dbup-oracle/OracleCommandReader.cs @@ -20,7 +20,8 @@ public class OracleCommandReader : SqlCommandReader /// Hook to support custom statements /// protected override bool IsCustomStatement => TryPeek(DelimiterKeyword.Length, out var statement) && - string.Equals(DelimiterKeyword, statement, StringComparison.OrdinalIgnoreCase); + string.Equals(DelimiterKeyword, statement, StringComparison.OrdinalIgnoreCase) && + string.IsNullOrEmpty(GetCurrentCommandTextFromBuffer()); /// /// Read a custom statement diff --git a/src/dbup-oracle/OracleCustomDelimiterCommandReader.cs b/src/dbup-oracle/OracleCustomDelimiterCommandReader.cs index d2278a1..cfc1d33 100644 --- a/src/dbup-oracle/OracleCustomDelimiterCommandReader.cs +++ b/src/dbup-oracle/OracleCustomDelimiterCommandReader.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using DbUp.Support; @@ -20,7 +20,8 @@ public OracleCustomDelimiterCommandReader(string sqlText, char delimiter) : base /// protected override bool IsCustomStatement => TryPeek(DelimiterKeyword.Length - 1, out var statement) && - string.Equals(DelimiterKeyword, CurrentChar + statement, StringComparison.OrdinalIgnoreCase); + string.Equals(DelimiterKeyword, CurrentChar + statement, StringComparison.OrdinalIgnoreCase) && + string.IsNullOrEmpty(GetCurrentCommandTextFromBuffer()); /// /// Read a custom statement diff --git a/src/dbup-oracle/OracleExtensions.cs b/src/dbup-oracle/OracleExtensions.cs index fc2def0..75a752f 100644 --- a/src/dbup-oracle/OracleExtensions.cs +++ b/src/dbup-oracle/OracleExtensions.cs @@ -170,6 +170,19 @@ public static UpgradeEngineBuilder OracleDatabase(IConnectionManager connectionM builder.WithPreprocessor(new OraclePreprocessor()); return builder; } + + /// + /// Tracks the list of executed scripts in an Oracle table. + /// + /// The builder. + /// The schema. + /// The table. + /// + public static UpgradeEngineBuilder JournalToOracleTable(this UpgradeEngineBuilder builder, string schema, string table) + { + builder.Configure(c => c.Journal = new OracleTableJournal(() => c.ConnectionManager, () => c.Log, schema, table)); + return builder; + } } #pragma warning restore IDE0060 // Remove unused parameter } diff --git a/src/dbup-oracle/OracleScriptExecutor.cs b/src/dbup-oracle/OracleScriptExecutor.cs index 33be0fb..f8442c2 100644 --- a/src/dbup-oracle/OracleScriptExecutor.cs +++ b/src/dbup-oracle/OracleScriptExecutor.cs @@ -47,10 +47,10 @@ protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScri } catch (OracleException exception) { - Log().WriteInformation("Oracle exception has occurred in script: '{0}'", script.Name); + Log().LogInformation("Oracle exception has occurred in script: '{0}'", script.Name); // OracleException.Number is the actual oracle error code - Log().WriteError("Script block number: {0}; Oracle error code: {1}; Message: {2}", index, exception.Number, exception.Message); - Log().WriteError(exception.ToString()); + Log().LogError("Script block number: {0}; Oracle error code: {1}; Message: {2}", index, exception.Number, exception.Message); + Log().LogError(exception.ToString()); throw; } } diff --git a/src/dbup-oracle/OracleTableJournal.cs b/src/dbup-oracle/OracleTableJournal.cs index 412f912..e2d6625 100644 --- a/src/dbup-oracle/OracleTableJournal.cs +++ b/src/dbup-oracle/OracleTableJournal.cs @@ -95,7 +95,7 @@ public override void EnsureTableExistsAndIsLatestVersion(Func dbComm { if (!journalExists && !DoesTableExist(dbCommandFactory)) { - Log().WriteInformation(string.Format("Creating the {0} table", FqSchemaTableName)); + Log().LogInformation("Creating the {0} table", FqSchemaTableName); // We will never change the schema of the initial table create. using (var command = GetCreateTableSequence(dbCommandFactory)) @@ -115,7 +115,7 @@ public override void EnsureTableExistsAndIsLatestVersion(Func dbComm command.ExecuteNonQuery(); } - Log().WriteInformation(string.Format("The {0} table has been created", FqSchemaTableName)); + Log().LogInformation("The {0} table has been created", FqSchemaTableName); OnTableCreated(dbCommandFactory); } diff --git a/src/dbup-oracle/dbup-oracle.csproj b/src/dbup-oracle/dbup-oracle.csproj index bbaeceb..b2afd84 100644 --- a/src/dbup-oracle/dbup-oracle.csproj +++ b/src/dbup-oracle/dbup-oracle.csproj @@ -6,7 +6,7 @@ DbUp Contributors DbUp Copyright © DbUp Contributors 2015 - netstandard2.0;net462 + netstandard2.1 dbup-oracle DbUp.Oracle dbup-oracle @@ -16,16 +16,15 @@ dbup-icon.png - - - - - - - + + true + true + embedded + - - + + +