efup 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet tool install --global efup --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local efup --version 0.0.1
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=efup&version=0.0.1
nuke :add-package efup --version 0.0.1

EFUP: Database migrations deployment + EF Core context/entities generation

Inspired by DbUp and EntityFrameworkCore.Generator, but radically simplified and reworked with the following changes/principles:

  • Don't make me think - the tool is self-documenting and easy to use.
  • No Yaml, the configuration is more restricted/opinionated and done mostly via command line options.
  • All generated files are located relative to a single target directory.
  • The target directory is fully cleaned and recreated on generation. The generated classes are partial and have hooks for manual customizations that live outside the target directory.
  • No view models/mapping/validators/query extensions/foreign keys (because YAGNI).
  • Optional System.Text.Json annotations;
  • Optional attribute annotations for generated entities;
  • Optional grouping of entities by schema.

Installation & usage

To install EFUP tool run the following command in the console

dotnet tool install --global EFUP

After the installation the efup command line tool will be available. Run efup --help to see available options and usage examples.

efup --help

Usage: efup [options]

Options:
  --version                                  Show version
                                             information.
  --help                                     Show help information.
  -p|--provider <Provider>                   A database provider.
                                             One of `SqlServer`
                                             (alias `MSSQL`/`ms`),
                                             `PostgreSQL`
                                             (`Postgres`, `pg`),
                                             `MySQL` (`my`) or
                                             `Sqlite` (case
                                             insensitive).
  -c|--connection-string <ConnectionString>  Database connection    
                                             string to reverse      
                                             engineer.
  -w|--workdir <WorkingDirectory>            A working directory    
                                             override. By default it
                                             is the current
                                             directory.
                                             Default value is:      
                                             D:\Dev\EfUp\src\EFUP\bin\Debug\net6.0.
  -d|--datadir <DataDir>                     A directory inside the 
                                             working directory where
                                             data context and       
                                             entities are generated.
                                             Default value is: EFUP.
  -m|--migrationsdir <MigrationsDir>         A directory inside the 
                                             working directory with 
                                             SQL migration files. If
                                             this option is missing 
                                             we use the directory   
                                             'DataDir/SQL' but only 
                                             if it is already       
                                             present.
  -n|--namespace <Namespace>                 Project namespace.     
  -i|--secret-id <UserSecretId>              A UserSecretsId to use.
                                             Default value is:      
                                             EFUPSharedUserSecretsId.
  -k|--secret-key <UserSecretKey>            A user secret key for a
                                             connection string.     
  -g|--group-by-schema                       Group entities by      
                                             schema.
  -x|--exclude-default-schema                Exclude the default    
                                             schema, e.g. `dbo` for 
                                             MSSQL or `public` for  
                                             PG.
  -j|--json                                  Add JSON attributes to 
                                             entities.
  -a|--attributes                            Use EF attribute       
                                             annotations where      
                                             possible.
  --schema-prefix                            Add schema name prefix 
                                             to entity names.       
  --strict                                   Enable strict mode: no 
                                             unused configs or      
                                             unknown schemas/tables.

Examples:

In the current working directory `WD` with a database data.db apply 
migrations from `WD/SQLMigrations` and generate EF context and entities in `WD/DbContextAndEntities`:

> efup -p sqlite -d DbContextAndEntities -m SQLMigrations -c "Data Source=data.db;"

Save connection string for future usage by a key. The presence of bo
th a connection string `-c` and a secrets key `-k` overwites the key
's value with the connection string. Other parameters are ignored. T
he `-i` parameter for UserSecretsId is optional. When it is missing the default shared key `EFUPSharedUserSecretsId` is used.

> efup -i MyUserSecretsId -k my_sqlite_conn_dev -c "Data Source=data.db;"

Use the secrets key instead of connection string:

> efup -p sqlite -d DbContextAndEntities -m SQLMigrations -i MyUserSecretsId -k my_sqlite_conn_dev


You could run EFUP tool automatically before project build by adding this section to a .csproj file:

  <Target Name="RunEFUP" BeforeTargets="Build">
    <Exec Command="dotnet efup -p sqlite -d Sakila -c 'Data Source=sakila_master.db;Version=3;' -w '$(ProjectDir)'"
          ContinueOnError="WarnAndContinue"
          WorkingDirectory="$(ProjectDir)" />
  </Target>
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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.

This package has no dependencies.

Version Downloads Last updated
0.0.2 518 10/22/2023
0.0.1 315 10/2/2023