CUSTIS.OracleIdempotentSqlGenerator 1.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package CUSTIS.OracleIdempotentSqlGenerator --version 1.0.2                
NuGet\Install-Package CUSTIS.OracleIdempotentSqlGenerator -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CUSTIS.OracleIdempotentSqlGenerator" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CUSTIS.OracleIdempotentSqlGenerator --version 1.0.2                
#r "nuget: CUSTIS.OracleIdempotentSqlGenerator, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install CUSTIS.OracleIdempotentSqlGenerator as a Cake Addin
#addin nuget:?package=CUSTIS.OracleIdempotentSqlGenerator&version=1.0.2

// Install CUSTIS.OracleIdempotentSqlGenerator as a Cake Tool
#tool nuget:?package=CUSTIS.OracleIdempotentSqlGenerator&version=1.0.2                

EF migrator isn't idempotent in case of using Oracle DB. Consider you have a migration which consists of 2 operations:

  • create table MY_TABLE1;
  • create table MY_TABLE2.

If the migration falls after 1-st statement, then Oracle DB will become inconclusive: each DDL in Oracle commits the transaction, so DB will contain MY_TABLE1. The migration could neither be run once more (as Oracle will fall on the attemp to create MY_TABLE1), nor rolled back (EF "thinks" that migration is not installed and won't get it down).

Idempotent SQL Generator for Oracle generates code, that could be rerun in case of failure. For example, it generates such a code for creating MY_COLUMN in MY_TABLE:

DECLARE
    i NUMBER;
BEGIN
    SELECT COUNT(*) INTO i
    FROM user_tab_columns
    WHERE table_name = UPPER('MY_TABLE') AND column_name = UPPER('MY_COLUMN');
    IF I != 1 THEN
        EXECUTE IMMEDIATE 'ALTER TABLE MY_TABLE ADD (MY_COLUMN DATE)';  
    END IF;       
END;

P.S. EF with MS SQL is idempotent out of the box. MS SQL has transactional DDL, which causes the migration to be fully installed or rolled back in case of error.

Usage

Just replace IMigrationsSqlGenerator when configuring DB Context:

public class MyDbContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.ReplaceService<IMigrationsSqlGenerator, IdempotentSqlGenerator>();
    }
}

Running tests

  • Open CMD at CUSTIS.OracleIdempotentSqlGenerator.Tests
  • Run:
    • dotnet user-secrets set DB ****
    • dotnet user-secrets set Schema ****
    • dotnet user-secrets set Pwd ****
  • Tests will run at Schema@DB, which could be any schema (even empty)

Known issues

At time of 2020-02-17 OracleMigrationsSqlGenerator has no support of RestartSequenceOperation. It generates the code, that couldn't be run on OracleDB (ALTER SEQUENCE...RESTART WITH). As Idempotent SqlGenerator inherits from OracleMigrationsSqlGenerator, it has the same problem.

Publish

  • Change version in CUSTIS.OracleIdempotentSqlGenerator
  • Pack CUSTIS.OracleIdempotentSqlGenerator
  • Upload it to nuget
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.5.4 312 10/16/2023
1.5.3 135 10/12/2023 1.5.3 is deprecated because it has critical bugs.
1.5.2 136 10/12/2023 1.5.2 is deprecated because it is no longer maintained.
1.5.1 2,695 6/17/2021
1.5.0 369 6/16/2021
1.4.1 347 6/15/2021
1.4.0 362 5/27/2021
1.3.0 357 5/3/2021
1.2.0 349 4/12/2021
1.1.0 410 3/20/2021
1.0.2 351 3/19/2021
1.0.1 780 2/18/2020
1.0.0 523 2/17/2020