danielwertheim / dotnet-sqldb

.NET Core Global Tool using e.g. DbUp to apply Db migrations for SQL-Server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dotnet-sqldb

Uses DbUp and Command Line Parser to offer a simple DotNet Global Tool for applying migration scripts etc. against a SQL-Server database.

Build status NuGet

Note: It's your data. Use at your own risk. As the license (MIT) says: "THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND..."

Installation

It's a DotNet Global Tool, distributed via NuGet.

Global installation

To install it globally (machine), you use the dotnet tool install command with the -g switch:

dotnet tool install -g dotnet-sqldb

After that you can start using it (you might need to restart your prompt of choice):

dotnet sqldb --help

or

dotnet-sqldb --help

Local installation

To install it locally, you use the dotnet tool install command with the --tool-path switch:

dotnet tool install dotnet-sqldb --tool-path /path/for/tool

To use it you will need to include it in the current environment path.

Commands

The following commands are supported:

  • Ensure: Ensures that the specified DB exists. If it does not exist, it gets created.
dotnet sqldb ensure [--connectionstring|-c]=mycnstring

or

dotnet-sqldb ensure [--connectionstring|-c]=mycnstring
  • Drop: Drops the specified database if it exists
dotnet sqldb drop [--connectionstring|-c]=mycnstring

or

dotnet-sqldb drop [--connectionstring|-c]=mycnstring
  • Up: Upgrades the database by applying SQL-scripts using DbUp
dotnet sqldb up [--connectionstring|-c]=mycnstring [--assembly|-a]=myassembly_with_embedded_scripts

or

dotnet-sqldb up [--connectionstring|-c]=mycnstring [--assembly|-a]=myassembly_with_embedded_scripts

Integration tests

The ./.env file and ./src/tests/IntegrationTests/integrationtests.local.ini files are .gitignored. In order to create sample files of these, you can run:

. init-local-config.sh

Docker-Compose

There's a docker-compose.yml file, that defines usage of an SQL Server instance over port 1401. The SA_PASSWORD is configured via environment key DNSQLDB_SA_PWD, which can either be specified via:

  • Environment variable: DNSQLDB_SA_PWD, e.g.:
DNSQLDB_SA_PWD=MyFooPassword
  • Docker Environment file ./.env (.gitignored), e.g.:
DNSQLDB_SA_PWD=MyFooPassword

Test configuration

A connection string needs to be provided, either via:

  • Local-INI-file (.gitignored): ./src/tests/IntegrationTests/integrationtests.local.ini containing a connection string section with a TestDb node, e.g.:
[ConnectionStrings]
TestDb="Server=.,1401;Database=foodb;User ID=sa;Password=MyFooPassword"
  • Environment variable: DNSQLDB_ConnectionStrings__TestDb, e.g.:
DNSQLDB_ConnectionStrings__TestDb=Server=.,1401;Database=foodb;User ID=sa;Password=MyFooPassword

About

.NET Core Global Tool using e.g. DbUp to apply Db migrations for SQL-Server

License:MIT License


Languages

Language:F# 62.3%Language:PowerShell 18.4%Language:C# 11.0%Language:Shell 8.3%