CUSTIS.OracleIdempotentSqlGenerator 1.4.0 Prefix Reserved

There is a newer version of this package available.
See the version list below for details.
Install-Package CUSTIS.OracleIdempotentSqlGenerator -Version 1.4.0
dotnet add package CUSTIS.OracleIdempotentSqlGenerator --version 1.4.0
<PackageReference Include="CUSTIS.OracleIdempotentSqlGenerator" Version="1.4.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add CUSTIS.OracleIdempotentSqlGenerator --version 1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CUSTIS.OracleIdempotentSqlGenerator, 1.4.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. 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.4.0

// Install CUSTIS.OracleIdempotentSqlGenerator as a Cake Tool
#tool nuget:?package=CUSTIS.OracleIdempotentSqlGenerator&version=1.4.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Idempotent SQL Generator for Oracle

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 (dotnet pack)
  • Upload it to nuget
  • Create release at GitHub

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.1 157 6/17/2021
1.5.0 114 6/16/2021
1.4.1 95 6/15/2021
1.4.0 134 5/27/2021
1.3.0 91 5/3/2021
1.2.0 88 4/12/2021
1.1.0 151 3/20/2021
1.0.2 90 3/19/2021
1.0.1 489 2/18/2020
1.0.0 269 2/17/2020