diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..7f188ab
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,51 @@
+name: "Code scanning - action"
+
+on:
+ push:
+ pull_request:
+ schedule:
+ - cron: '0 11 * * 5'
+
+jobs:
+ CodeQL-Build:
+
+ runs-on: ubuntu-latest
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+ with:
+ # We must fetch at least the immediate parents so that if this is
+ # a pull request then we can checkout the head.
+ fetch-depth: 2
+
+ # If this run was triggered by a pull request event, then checkout
+ # the head of the pull request instead of the merge commit.
+ - run: git checkout HEAD^2
+ if: ${{ github.event_name == 'pull_request' }}
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ # Override language selection by uncommenting this and choosing your languages
+ # with:
+ # languages: go, javascript, csharp, python, cpp, java
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v1
+
+ # ℹ️ Command-line programs to run using the OS shell.
+ # 📚 https://git.io/JvXDl
+
+ # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
diff --git a/.gitignore b/.gitignore
index f717ca9..55986f9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,5 @@ src/Ormico.DbPatchManager/bin/*
src/Ormico.DbPatchManager/obj/*
bin
obj
+
+src/Ormico.DbPatchManager.CLI/deb/
diff --git a/.hgignore b/.hgignore
deleted file mode 100644
index 9912a0a..0000000
--- a/.hgignore
+++ /dev/null
@@ -1,8 +0,0 @@
-syntax: glob
-src/.vs/*
-src/Ormico.DbPatchManager.Cmd/bin/*
-src/Ormico.DbPatchManager.Cmd/obj/*
-src/Ormico.DbPatchManager/obj/*
-src/Ormico.DbPatchManager/bin/*
-src/Ormico.DbPatchManager.SqlServer/bin/*
-src/Ormico.DbPatchManager.SqlServer/obj/*
diff --git a/LICENSE b/LICENSE
index 0401bfb..37c6207 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2019 Zack Moore
+Copyright (c) 2020 Zack Moore
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/README.md b/README.md
index e0d8601..290a72f 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,49 @@
+
# DB Patch Manager
Database development tool for change control.
-v2.0 has been updated to .NET Core for cross platform support.
+
+v2 has been updated to .NET Core for cross platform support.
DB Patch Manager supports database development across multiple source control branches by tracking the dependencies of each patch and installing them in the correct order. When a developer adds a new patch, that patch depends on all the previous patches recorded in that branch. When branches are merged the `patches.json` file is merged to include all patches and the dependency tree from each branch.
-Database changes are deployed using the `build` command. DB Patch Manager will check the database to determine which patches have already been installed before installing new patches in the correct order.
+## Installing
+### Windows
+dbpatch doesn't yet have working distribution package or an msi.
+
+1. Download the zip from the latest Release.
+2. Right click on the zip in Explorer and open the Properties dialog. Click the checkbox to Unblock the zip and then click OK. If you do not see an Unblock checkbox near the bottom of the dialog, then click OK and go to the next step.
+3. Unzip the zip file into a folder where you wish to install it. For example `C:\Program Files\dbpatch`
+4. Add the folder to your PATH.
+
+
+
+### Linux
+dbpatch doesn't yet have working distribution packages but can be installed using the included install shell script, or download and view the shell script if you wish to perform the steps manually.
+
+### Prerequisites
+* .NET 5
+* wget
+* unzip
+
+```
+wget -qO- https://github.com/ormico/dbpatchmanager/releases/latest/download/install-dbpatch.sh | bash
+```
+
+or
+
+```
+wget -q https://github.com/ormico/dbpatchmanager/releases/latest/download/install-dbpatch.sh -O install-dbpatch.sh
+chmod +x install-dbpatch.sh
+./install-dbpatch.sh
+rm install-dbpatch.sh
+```
+
+If you install dbpatch to somewhere other than `/usr/local/lib/dbpatch` you may need to modify `/usr/local/lib/dbpatch/dbpatch` This file is a shell script which wraps the call to the .net commandline which is used to run dbpatch.dll.
+
+If you wish to install a version other than latest, each Release comes with an install shell script specific for that version starting with v2.1.1
## Create new db project
-```PS C:\MyProject> .\dbpatch init --dbtype "Ormico.DbPatchManager.SqlServer.dll, Ormico.DbPatchManager.SqlServer.SqlDatabase"```
+```MyProject> dbpatch init --dbtype sqlserver```
This will create a new project file named `patches.json` and initilize it to the SQL Server plugin.
@@ -22,9 +58,9 @@ Create a new file named `patches.local.json` When you are a adding files to sour
Each developer would enter their local connection string. When deploying, you would enter the production server's connection string.
## Add a database patch
-```PS C:\MyProject> .\dbpatch addpatch --name TestPatch```
+```MyProject> dbpatch addpatch -n TestPatch```
-Creates a folder for the patch in `C:\MyProject\Patches\` and adds the patch to the patches.json file. The folder is named using a date time string and a random number and the name. For example something like `201708011412-2403-testpatch`. User can place .sql files in the patch folder and they will be run when the patch is applied. If the user includes more than one patch file, they are run in alphabetical order.
+Creates a folder for the patch in `...\MyProject\Patches\` and adds the patch to the patches.json file. The folder is named using a date time string and a random number and the name. For example something like `201708011412-2403-testpatch`. User can place .sql files in the patch folder and they will be run when the patch is applied. If the user includes more than one patch file, they are run in alphabetical order.
## Add a database code item
Code items are database items that are applied on each build instead of only once like patches. Typically code items are Stored Procedures, Functions, Views, and Triggers.
@@ -48,7 +84,7 @@ The default list of code file extensions and the order they load is:
* .trigger3.sql - Trigger
## Build Database
-```PS C:\MyProject> .\dbpatch build```
+```MyProject> dbpatch build```
Applies all missing patches and runs all code files.
diff --git a/assets/dbpatch-manager-profile.png b/assets/dbpatch-manager-profile.png
new file mode 100644
index 0000000..c99b25e
Binary files /dev/null and b/assets/dbpatch-manager-profile.png differ
diff --git a/assets/rect-logo-small.png b/assets/rect-logo-small.png
new file mode 100644
index 0000000..ff148c1
Binary files /dev/null and b/assets/rect-logo-small.png differ
diff --git a/assets/rect-logo.png b/assets/rect-logo.png
new file mode 100644
index 0000000..b3b44b2
Binary files /dev/null and b/assets/rect-logo.png differ
diff --git a/assets/repository-open-graph-template.pdn b/assets/repository-open-graph-template.pdn
new file mode 100644
index 0000000..44246dc
Binary files /dev/null and b/assets/repository-open-graph-template.pdn differ
diff --git a/assets/repository-open-graph.png b/assets/repository-open-graph.png
new file mode 100644
index 0000000..c944842
Binary files /dev/null and b/assets/repository-open-graph.png differ
diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 57984e6..9188e82 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -5,7 +5,7 @@ pool:
variables:
system.debug: true
buildConfiguration: 'Release'
- Version: '2.0.0.$(Build.BuildID)'
+ Version: '2.1.0.$(Build.BuildID)'
steps:
- bash: echo v$(Version)
- task: DotNetCoreCLI@2
@@ -21,5 +21,5 @@ steps:
artifactName: nuget-artifacts
- task: PublishBuildArtifacts@1
inputs:
- pathtoPublish: 'src/Ormico.DbPatchManager.CLI/bin/release/netcoreapp2.2/publish/'
+ pathtoPublish: 'src/Ormico.DbPatchManager.CLI/bin/release/netcoreapp3.1/publish/'
artifactName: zip-artifacts
diff --git a/docs/tutorial-testdbtype.md b/docs/tutorial-testdbtype.md
new file mode 100644
index 0000000..3872179
--- /dev/null
+++ b/docs/tutorial-testdbtype.md
@@ -0,0 +1,8 @@
+-> I am considering moving the section on the Test Db to a separate document
+## Creating a new Project (Test Db Type)
+### Setting the database type
+### Setting the database Connection String
+### Creating the first Patches
+### Building the Database
+### Merging schema changes from another user
+### Creating the first Database Code entries
diff --git a/docs/tutorial.md b/docs/tutorial.md
new file mode 100644
index 0000000..02218fe
--- /dev/null
+++ b/docs/tutorial.md
@@ -0,0 +1,191 @@
+# Tutorial
+## Intro
+dbpatch is a tool for database change management. The purpose of the tool is to manage database change patches and code assets. These patches and code assets can then be added to and modified in multiple source control branches, merged, and applied to a database in the proper order.
+
+## Installing
+Before using dbpatch, it must be installed on a workstation or server.
+
+dbpatch is compiled on .NET 5 which is cross platform and runs on Windows, Linux, and MacOS.
+
+### Installing on Windows
+dbpatch doesn't yet have a working distribution package or msi for Windows. Instead use the following instructions.
+
+[.NET 5 runtime](https://dotnet.microsoft.com/download/dotnet/5.0) is a requirement that must be installed before dbpatch can be used.
+
+1. Download the zip from the latest [Release](https://github.com/ormico/dbpatchmanager/releases/latest/download/dbpatch.zip).
+2. Right click on the zip in Explorer and open the Properties dialog. Click the checkbox to Unblock the zip and then click OK. If you do not see an Unblock checkbox near the bottom of the dialog, then click OK and go to the next step.
+3. Unzip the zip file into a folder where you wish to install it. For example `C:\Program Files\dbpatch`
+4. Add the folder to your PATH.
+
+
+
+### Installing on Linux
+//todo: I tested on an Ubuntu docker container, WSL Ubuntu.
+//todo: Need to update sudo usage in instructions.
+
+dbpatch doesn't yet have working distribution packages but can be installed using the included install shell script, or download and view the shell script if you wish to perform the steps manually.
+
+#### Prerequisites
+* [.NET 5 runtime](https://dotnet.microsoft.com/download/dotnet/5.0)
+* [wget](https://www.gnu.org/software/wget/)
+* unzip
+
+#### Steps
+Using `wget`, the install shell script can be downloaded and piped to bash to perform the install. This is the quickest way to get dbpatch installed, but it requires trusting the install script.
+```
+wget -qO- https://github.com/ormico/dbpatchmanager/releases/latest/download/install-dbpatch.sh | sudo bash
+```
+Or, you can download the install script and review it's contents before running.
+```
+#download install-dbpatch.sh
+wget -q https://github.com/ormico/dbpatchmanager/releases/latest/download/install-dbpatch.sh -O install-dbpatch.sh
+#review install-dbpatch.sh code before executing
+cat install-dbpatch.sh
+#set install-dbpatch.sh as executable
+chmod +x install-dbpatch.sh
+#run install-dbpatch.sh
+./install-dbpatch.sh
+#cleanup
+rm install-dbpatch.sh
+```
+
+If you install dbpatch to a location other than `/usr/local/lib/dbpatch` you may need to modify `/usr/local/lib/dbpatch/dbpatch`. This file is a shell script which wraps the call to `dotnet dbpatch.dll`.
+
+If you wish to install a version other than latest, each Release comes with an install shell script specific for that version starting with v2.1.1
+
+### Installing on MacOS
+I haven't tested this on MacOS yet, but the Linux install instructions should be similar.
+
+## Our Example Developers
+In this tutorial, we are going to simulate a multi-developer team working in git and SQL Server. To simulate the team collaborating together in git, we will check the changes attributed to each of our imaginary team members into a different branch.
+
+Our Imaginary Team:
+* Ann - working on user login and privilege system
+* Bettie - working on order tracking system
+* Casey - initial project setup and PR review and merge
+
+## Creating a new Project (SQL Server)
+To get started, create a folder for the the database project. In that folder run `dbpatch init` and specify the `--dbtype` parameter. For this example, specify a MS SQL Server database by using `sqlserver` as the dbtype value.
+
+```
+mkdir mydb
+cd mydb
+git init
+dbpatch init --dbtype sqlserver
+````
+This will create the initial starting folders and files which include:
+* A `Code` folder for stored procedures, triggers, and other executable parts of a database.
+* A `Patches` folder to hold each change script.
+* A `patches.json` file which holds the configuration as well as the patch dependency graph.
+
+### Create an empty database
+dbpatch requires that a database exists for it to connect to. dbpatch will not create the database for you if it does not exist.
+
+In our example, we are using `sqlcmd` from the command line to create our example database but any SQL Server tool that can execute scripts will do. Execute the following from the command line.
+
+```
+sqlcmd -S . -Q "create database [dbpatch-example-ann]"
+sqlcmd -S . -Q "create database [dbpatch-example-bettie]"
+sqlcmd -S . -Q "create database [dbpatch-example-casey]"
+```
+
+Because we have three developers on our team, lets give each of them their own database to work in. This simulates each of them having a local database on their own workstation.
+
+### Setting the database Connection String
+dbpatch's configution system supports splitting the configuration information into two files. In the previous step, we created `patches.json` using the `init` command.
+
+In this step, we are going to create the second file `patches.local.json`. Where `patches.json` is checked into source control, `patches.local.json` is designed not to be checked in. The local file is where workstation or server specific settings are specified. When dbpatch runs, these two configuration files are merged with `patches.local.json` overriding any settings made in `patches.json`. While you can override any setting, typically the `ConnectionString` is the most common setting used in the local file.
+
+Create a file in the database project folder named `patches.local.json`. The contents of the file should look like the following, but in place of this connection string specify the connection string to your development database. This is usually a database and server running on your local workstation.
+
+```
+{
+ "ConnectionString": "Server=.;Database=dbpatch-example-casey;Trusted_Connection=True;"
+}
+```
+
+For our imaginary team, lets create a separate local file for each developer. We can swap this file in and out as we simulate commands for each individual. Create the following three files using the correct connection strings for your workstation.
+
+`patches.ann-local.json`
+```
+{
+ "ConnectionString": "Server=.;Database=dbpatch-example-ann;Trusted_Connection=True;"
+}
+```
+
+`patches.bettie-local.json`
+```
+{
+ "ConnectionString": "Server=.;Database=dbpatch-example-bettie;Trusted_Connection=True;"
+}
+```
+
+`patches.casey-local.json`
+```
+{
+ "ConnectionString": "Server=.;Database=dbpatch-example-casey;Trusted_Connection=True;"
+}
+```
+
+### Ignoring patches.local.json and checking in changes in source control
+The file `patches.local.json` should be added to `.gitignore` to prevent it from being checked in. In addition to containing sensitive login information, `patches.local.json` is used to customize the login for each environment.
+
+For this example we also want to ignore the other patches local files we created for each imaginary team member.
+
+Create a `.gitignore` file that contains the following entries.
+
+`.gitignore`
+```
+patches.local.json
+patches.ann-local.json
+patches.bettie-local.json
+patches.casey-local.json
+```
+
+Check in the files we have created so far (except for the ones that are ignored).
+
+```
+git stage *
+git commit -m "init dbpatch project"
+```
+
+## Creating the first Patches
+
+```dbpatch addpatch -n first-patch```
+
+```202103082324-1408-first-patch```
+```
+git branch casey/db-initial-setup
+git checkout casey/db-initial-setup
+git stage *
+git commit -m "first patch"
+```
+
+
+//todo: decide what kind of db we are building and create the final whole project in an example repo or folder. make a schema diagram and post it in this example
+
+### Building the Database after Schema additions
+
+//todo: make sure dbpatch doesn't do anything if patches.json is not in current folder
+```dbpatch build```
+
+## Merging schema changes from another user
+### Building the Database after Schema merge
+
+## Examining InstalledPatches table
+//todo: add order by installed date column and show query results
+```sqlcmd -S . -d dbpatch-example -Q "select * from installedpatches"```
+
+## Creating the first Database Code entries
+### Stored Procedures
+### User Defined Functions
+### User Defined Function with Dependencies
+### Triggers
+### Building the Database after Code additions
+
+## Merging Code entries
+### Building the Database after Code merge
+
+# Deploying changes to production
+
+# Conclusion
diff --git a/docs/unblock-zip.png b/docs/unblock-zip.png
new file mode 100644
index 0000000..3c1c7e8
Binary files /dev/null and b/docs/unblock-zip.png differ
diff --git a/src/Ormico.DbPatchManager.CLI/CommandLineOptions/AddPatchCmdLineOptions.cs b/src/Ormico.DbPatchManager.CLI/CommandLineOptions/AddPatchCmdLineOptions.cs
index c159931..6eb8cd9 100644
--- a/src/Ormico.DbPatchManager.CLI/CommandLineOptions/AddPatchCmdLineOptions.cs
+++ b/src/Ormico.DbPatchManager.CLI/CommandLineOptions/AddPatchCmdLineOptions.cs
@@ -9,7 +9,7 @@ public AddPatchCmdLineOptions()
{
}
- [Option("name", HelpText = "patch name")]
+ [Option('n', "name", HelpText = "patch name")]
public string Name { get; set; }
}
}
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.CLI/Ormico.DbPatchManager.CLI.csproj b/src/Ormico.DbPatchManager.CLI/Ormico.DbPatchManager.CLI.csproj
index 13746a7..6b4ab7a 100644
--- a/src/Ormico.DbPatchManager.CLI/Ormico.DbPatchManager.CLI.csproj
+++ b/src/Ormico.DbPatchManager.CLI/Ormico.DbPatchManager.CLI.csproj
@@ -1,26 +1,36 @@
-
-
+
Exe
- netcoreapp2.2
- true
+ net8.0
+ True
true
LICENSE
https://github.com/ormico/dbpatchmanager
- Copyright (c) 2020 Zack Moore
+ Copyright (c) 2023 Zack Moore
Zack Moore
Ormico
Ormico DB Patch Manager CLI
dbpatch
Ormico.DbPatchManager.CLI
- https://dbpatch.dev
+ https://dbpatch.dev/
+ 2.2.0
+ dbpatch-manager-profile.png
+ Command Line Interface for Database Change managment designed for multi-dev/multi-branch.
-
+
+
+
+
+
+
+ True
+
+
+
-
PreserveNewest
@@ -29,20 +39,17 @@
PreserveNewest
-
-
+
-
-
True
-
+
+
-
-
+
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.CLI/Properties/PublishProfiles/FolderProfile.pubxml b/src/Ormico.DbPatchManager.CLI/Properties/PublishProfiles/FolderProfile.pubxml
index acc147b..e238915 100644
--- a/src/Ormico.DbPatchManager.CLI/Properties/PublishProfiles/FolderProfile.pubxml
+++ b/src/Ormico.DbPatchManager.CLI/Properties/PublishProfiles/FolderProfile.pubxml
@@ -7,7 +7,8 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
FileSystem
Release
Any CPU
- netcoreapp2.2
- bin\Release\netcoreapp2.2\publish\
+ net8.0
+ bin\Release\net8\publish\
+ false
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.CLI/dbpatch b/src/Ormico.DbPatchManager.CLI/dbpatch
index f30ec68..43934eb 100644
--- a/src/Ormico.DbPatchManager.CLI/dbpatch
+++ b/src/Ormico.DbPatchManager.CLI/dbpatch
@@ -1,4 +1,5 @@
#!/bin/sh
-dotnet ./dbpatch.dll "$@"
+# if this isn't working try 'dos2unix dbpatch'
+dotnet /usr/local/lib/dbpatch/dbpatch.dll "$@"
rc=$?
exit $rc
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Logic/DatabaseOptions.cs b/src/Ormico.DbPatchManager.Common/DatabaseOptions.cs
similarity index 93%
rename from src/Ormico.DbPatchManager.Logic/DatabaseOptions.cs
rename to src/Ormico.DbPatchManager.Common/DatabaseOptions.cs
index 417fb2f..89cb4ed 100644
--- a/src/Ormico.DbPatchManager.Logic/DatabaseOptions.cs
+++ b/src/Ormico.DbPatchManager.Common/DatabaseOptions.cs
@@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;
-namespace Ormico.DbPatchManager.Logic
+namespace Ormico.DbPatchManager.Common
{
public struct DatabaseOptions
{
diff --git a/src/Ormico.DbPatchManager.Common/DbPatchManagerException.cs b/src/Ormico.DbPatchManager.Common/DbPatchManagerException.cs
new file mode 100644
index 0000000..69e11de
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Common/DbPatchManagerException.cs
@@ -0,0 +1,19 @@
+using System;
+
+namespace Ormico.DbPatchManager.Common
+{
+ public class DbPatchManagerException : Exception
+ {
+ public DbPatchManagerException() : base()
+ {
+ }
+
+ public DbPatchManagerException(string message) : base(message)
+ {
+ }
+
+ public DbPatchManagerException(string message, Exception innerException) : base(message, innerException)
+ {
+ }
+ }
+}
diff --git a/src/Ormico.DbPatchManager.Logic/IDatabase.cs b/src/Ormico.DbPatchManager.Common/IDatabase.cs
similarity index 91%
rename from src/Ormico.DbPatchManager.Logic/IDatabase.cs
rename to src/Ormico.DbPatchManager.Common/IDatabase.cs
index 7ffb5aa..0da346c 100644
--- a/src/Ormico.DbPatchManager.Logic/IDatabase.cs
+++ b/src/Ormico.DbPatchManager.Common/IDatabase.cs
@@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;
-namespace Ormico.DbPatchManager.Logic
+namespace Ormico.DbPatchManager.Common
{
public interface IDatabase: IDisposable
{
diff --git a/src/Ormico.DbPatchManager.Logic/InstalledPatchInfo.cs b/src/Ormico.DbPatchManager.Common/InstalledPatchInfo.cs
similarity index 87%
rename from src/Ormico.DbPatchManager.Logic/InstalledPatchInfo.cs
rename to src/Ormico.DbPatchManager.Common/InstalledPatchInfo.cs
index 4c4a073..c6cc358 100644
--- a/src/Ormico.DbPatchManager.Logic/InstalledPatchInfo.cs
+++ b/src/Ormico.DbPatchManager.Common/InstalledPatchInfo.cs
@@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;
-namespace Ormico.DbPatchManager.Logic
+namespace Ormico.DbPatchManager.Common
{
public class InstalledPatchInfo
{
diff --git a/src/Ormico.DbPatchManager.Common/Ormico.DbPatchManager.Common.csproj b/src/Ormico.DbPatchManager.Common/Ormico.DbPatchManager.Common.csproj
new file mode 100644
index 0000000..8805154
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Common/Ormico.DbPatchManager.Common.csproj
@@ -0,0 +1,29 @@
+
+
+ net8.0
+ https://github.com/ormico/dbpatchmanager
+ LICENSE
+ Zack Moore
+ Ormico
+ true
+ Ormico DB Patch Manager Common
+ dbpatch-manager-profile.png
+ true
+ Classes and interfaces used to implement a DB Patch Manager Database Module.
+ Copyright (c) 2023 Zack Moore
+ https://dbpatch.dev/
+ 2.2.0
+
+
+
+ True
+
+
+
+
+ True
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Common/Properties/PublishProfiles/FolderProfile.pubxml b/src/Ormico.DbPatchManager.Common/Properties/PublishProfiles/FolderProfile.pubxml
new file mode 100644
index 0000000..df5633a
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Common/Properties/PublishProfiles/FolderProfile.pubxml
@@ -0,0 +1,13 @@
+
+
+
+
+ Release
+ Any CPU
+ bin\Release\net8.0\publish\
+ FileSystem
+ <_TargetId>Folder
+
+
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Logic.Tests/BuildConfigurationWriterTests.cs b/src/Ormico.DbPatchManager.Logic.Tests/BuildConfigurationWriterTests.cs
new file mode 100644
index 0000000..6494027
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Logic.Tests/BuildConfigurationWriterTests.cs
@@ -0,0 +1,235 @@
+using NUnit.Framework;
+using Ormico.DbPatchManager.Logic;
+using System;
+using System.Collections.Generic;
+using System.IO.Abstractions.TestingHelpers;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ormico.DbPatchManager.Logic.Tests
+{
+ internal class BuildConfigurationWriterTests
+ {
+ [SetUp]
+ public void Setup()
+ {
+ }
+
+ const string patchesJson = @"{
+ ""DatabaseType"": ""sqlserver"",
+ ""ConnectionString"": null,
+ ""CodeFolder"": ""Code"",
+ ""CodeFiles"": [
+ ""*.view.sql"",
+ ""*.udf.sql"",
+ ""*.view2.sql"",
+ ""*.udf2.sql"",
+ ""*.view3.sql"",
+ ""*.udf3.sql"",
+ ""*.sproc.sql"",
+ ""*.sproc2.sql"",
+ ""*.sproc3.sql"",
+ ""*.trigger.sql"",
+ ""*.trigger2.sql"",
+ ""*.trigger3.sql""
+ ],
+ ""PatchFolder"": ""Patches"",
+ ""patches"": [
+ {
+ ""id"": ""202311262317-6854-first-tables"",
+ ""dependsOn"": []
+ }
+ ]
+}";
+ const string patchesJsonWSchema = @"{
+ ""$schema"": ""http://dbpatch.com/json-schema/ormico-dbpatch-v1.json"",
+ ""DatabaseType"": ""sqlserver"",
+ ""ConnectionString"": null,
+ ""CodeFolder"": ""Code"",
+ ""CodeFiles"": [
+ ""*.view.sql"",
+ ""*.udf.sql"",
+ ""*.view2.sql"",
+ ""*.udf2.sql"",
+ ""*.view3.sql"",
+ ""*.udf3.sql"",
+ ""*.sproc.sql"",
+ ""*.sproc2.sql"",
+ ""*.sproc3.sql"",
+ ""*.trigger.sql"",
+ ""*.trigger2.sql"",
+ ""*.trigger3.sql""
+ ],
+ ""PatchFolder"": ""Patches"",
+ ""patches"": [
+ {
+ ""id"": ""202311262317-6854-first-tables"",
+ ""dependsOn"": []
+ }
+ ]
+}";
+ const string patchesJsonWUnknownSchema = @"{
+ ""$schema"": ""http://dbpatch.com/json-schema/ormico-dbpatch-v2.json"",
+ ""DatabaseType"": ""sqlserver"",
+ ""PatchFolder"": ""Patches""
+}";
+ const string shortPatchesJson = @"{
+ ""DatabaseType"": ""sqlserver"",
+ ""PatchFolder"": ""Patches""
+}";
+ const string patchesLocalJson = @"{
+ ""DatabaseType"": ""sqlserver"",
+ ""ConnectionString"": ""Server=devServer;Database=DevDataBase;Trusted_Connection=True;""
+}";
+ private const string ExpectedReadApplicationExceptionText = "Configuration file does not exist. Call init first.";
+
+ [Test]
+ public void DetectSchemaVersion_WhenSchemaPropertyIsSet()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData("{ }") },
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var o = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(patchesJsonWSchema);
+
+ var result = bcw.DetectSchemaVersion(o);
+
+ Assert.That(result, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.DbPatchV1));
+ }
+
+ [Test]
+ public void DetectSchemaVersion_WhenSchemaPropertyIsSetButItIsAnUnknownSchema()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData("{ }") },
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var o = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(patchesJsonWUnknownSchema);
+
+ var result = bcw.DetectSchemaVersion(o);
+
+ Assert.That(result, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.Unknown));
+ }
+
+ [Test]
+ public void DetectSchemaVersion_WhenNoSchemaPropertyIsSetDetectSchemaByOtherProperties()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData("{ }") },
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var o = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(patchesJson);
+
+ var result = bcw.DetectSchemaVersion(o);
+
+ Assert.That(result, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.DbPatchV1));
+ }
+
+ [Test]
+ public void DetectSchemaVersion_WhenNoSchemaPropertyIsSetAndThereArentEnoughOtherPropertiesToDetect()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData("{ }") },
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var o = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(shortPatchesJson);
+
+ var result = bcw.DetectSchemaVersion(o);
+
+ Assert.That(result, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.Unknown));
+
+ Assert.Pass();
+ }
+
+ [Test]
+ public void Read_WhenFileDoesNotExist()
+ {
+ //todo: use https://github.com/TestableIO/System.IO.Abstractions/blob/main/tests/TestableIO.System.IO.Abstractions.TestingHelpers.Tests/MockFileWriteAllTextTests.cs
+ // for examples on how to uses MockFileSystem to test file system operations
+
+ // Arrange
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+
+ // Act
+ //todo: test if null is passed to the constructor as patch and local patch file paths
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ // Assert
+ Assert.Throws(Is.TypeOf().And.Message.EqualTo(ExpectedReadApplicationExceptionText),
+ () => bcw.Read());
+ }
+
+ [Test]
+ public void Read_WhenFileExists()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData(patchesJson) },
+ { @"\databaseproj\patches.local.json", new MockFileData("{ }") }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var result = bcw.Read();
+
+ Assert.That(result.DatabaseType, Is.EqualTo("sqlserver"));
+ Assert.That(result.CodeFiles[2], Is.EqualTo("*.view2.sql"));
+ Assert.That(result.CodeFolder, Is.EqualTo("Code"));
+ Assert.That(result.PatchFolder, Is.EqualTo("Patches"));
+ Assert.That(result.patches.Count, Is.EqualTo(1));
+ }
+
+ [Test]
+ public void Read_WhenNoLocalFileExists()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData(patchesJson) }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var result = bcw.Read();
+
+ Assert.That(result.DatabaseType, Is.EqualTo("sqlserver"));
+ Assert.That(result.CodeFiles[2], Is.EqualTo("*.view2.sql"));
+ Assert.That(result.CodeFolder, Is.EqualTo("Code"));
+ Assert.That(result.PatchFolder, Is.EqualTo("Patches"));
+ Assert.That(result.patches.Count, Is.EqualTo(1));
+ }
+
+ [Test]
+ public void Read_WhenLocalFileExists()
+ {
+ var mockFileSystem = new MockFileSystem(new Dictionary
+ {
+ { @"\databaseproj\patches.json", new MockFileData(patchesJson) },
+ { @"\databaseproj\patches.local.json", new MockFileData(patchesLocalJson) }
+ });
+ var bcw = new BuildConfigurationWriter(@"\databaseproj\patches.json", @"\databaseproj\patches.local.json", mockFileSystem);
+
+ var result = bcw.Read();
+
+ Assert.That(result.DatabaseType, Is.EqualTo("sqlserver"));
+ Assert.That(result.CodeFiles[2], Is.EqualTo("*.view2.sql"));
+ Assert.That(result.CodeFolder, Is.EqualTo("Code"));
+ Assert.That(result.PatchFolder, Is.EqualTo("Patches"));
+ Assert.That(result.ConnectionString, Is.EqualTo("Server=devServer;Database=DevDataBase;Trusted_Connection=True;"));
+ Assert.That(result.patches.Count, Is.EqualTo(1));
+ }
+ }
+}
diff --git a/src/Ormico.DbPatchManager.Logic.Tests/Ormico.DbPatchManager.Logic.Tests.csproj b/src/Ormico.DbPatchManager.Logic.Tests/Ormico.DbPatchManager.Logic.Tests.csproj
index f3e5e8e..97febac 100644
--- a/src/Ormico.DbPatchManager.Logic.Tests/Ormico.DbPatchManager.Logic.Tests.csproj
+++ b/src/Ormico.DbPatchManager.Logic.Tests/Ormico.DbPatchManager.Logic.Tests.csproj
@@ -1,19 +1,15 @@
-
- netcoreapp2.2
-
+ net8.0
false
-
-
-
-
+
+
+
+
-
-
-
+
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Logic.Tests/README.md b/src/Ormico.DbPatchManager.Logic.Tests/README.md
new file mode 100644
index 0000000..2f58417
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Logic.Tests/README.md
@@ -0,0 +1,22 @@
+# Ormico DB PatchManager Logic Unit Tests Readme
+
+## Overview
+
+## Test Framework
+NUnit
+
+## Test Naming Conventions
+
+Test naming is flexible and is not required to strictly follow the below conventions. However, the following conventions are recommended:
+
+`[UnitOfWork or MethodName]_[Short description of what is being tested]`
+
+Examples:
+* `public void GetPatch_ReturnsPatch()`
+* `public void GetPatch_WhenPatchDoesNotExist()`
+* `public void MapSchemaVersion_WhenSchemaVersionDoesNotExist()`
+* `public void MapSchemaVersion_WhenSchemaVersionExists()`
+
+One consequence of this naming convention is that if the method name changes, the test name will not match the new method name unless it is manually changed or refactoring tools become capable enough to do it automatically.
+
+Underscores are not required if PascalCase is used for the description portion of the test name, but are recomended if it is necessary to add an addtional section to the test name.
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Logic.Tests/SchemaMapperTests.cs b/src/Ormico.DbPatchManager.Logic.Tests/SchemaMapperTests.cs
new file mode 100644
index 0000000..04e21e7
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Logic.Tests/SchemaMapperTests.cs
@@ -0,0 +1,36 @@
+using NUnit.Framework;
+using Ormico.DbPatchManager.Logic;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ormico.DbPatchManager.Logic.Tests
+{
+ internal class SchemaMapperTests
+ {
+ [SetUp]
+ public void Setup()
+ {
+ }
+
+ [Test]
+ public void MapSchemaVersion_WhenSchemaVersionExists()
+ {
+ var schemaMapper = new SchemaMapper();
+ var enumResult = schemaMapper.MapSchemaVersion(SchemaMapper.PatchesSchemaVersionId.DbPatchV1);
+
+ Assert.That(enumResult, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.DbPatchV1));
+ }
+
+ [Test]
+ public void MapSchemaVersion_WhenSchemaVersionDoesNotExist()
+ {
+ var schemaMapper = new SchemaMapper();
+ var enumResult = schemaMapper.MapSchemaVersion("https://example.com/json-schema/does-not-exist.json");
+
+ Assert.That(enumResult, Is.EqualTo(SchemaMapper.PatchesSchemaVersionEnum.Unknown));
+ }
+ }
+}
diff --git a/src/Ormico.DbPatchManager.Logic.Tests/UnitTest1.cs b/src/Ormico.DbPatchManager.Logic.Tests/UnitTest1.cs
deleted file mode 100644
index 0008e77..0000000
--- a/src/Ormico.DbPatchManager.Logic.Tests/UnitTest1.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-
-namespace Ormico.DbPatchManager.Logic.Tests
-{
- [TestClass]
- public class UnitTest1
- {
- [TestMethod]
- public void TestMethod1()
- {
- }
- }
-}
diff --git a/src/Ormico.DbPatchManager.Logic/BuildConfigurationWriter.cs b/src/Ormico.DbPatchManager.Logic/BuildConfigurationWriter.cs
index dba9bb5..cedb2d6 100644
--- a/src/Ormico.DbPatchManager.Logic/BuildConfigurationWriter.cs
+++ b/src/Ormico.DbPatchManager.Logic/BuildConfigurationWriter.cs
@@ -1,29 +1,35 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using Ormico.DbPatchManager.Common;
using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Ormico.DbPatchManager.Logic
{
///
- /// Readn and Write DatabaseBuildConfiguration to storage.
+ /// Read and Write DatabaseBuildConfiguration to storage.
///
public class BuildConfigurationWriter
{
- public BuildConfigurationWriter(string filePath, string localFilePath)
+ ///
+ ///
+ ///
+ /// Path and filename for main settings file.
+ /// Path and filename for local override settings file.
+ /// File system object for unit testing.
+ public BuildConfigurationWriter(string filePath, string localFilePath, IFileSystem fileSystem = null)
{
_filePath = filePath;
_localFilePath = localFilePath;
+ _io = fileSystem ?? new FileSystem();
}
///
/// Use System.IO.Abstraction to make testing easier.
///
- FileSystem _io = new FileSystem();
+ IFileSystem _io;
///
/// Path and name of file to read and write.
@@ -48,9 +54,12 @@ public DatabaseBuildConfiguration Read()
DatabaseBuildConfiguration rc = null;
if(_io.File.Exists(_filePath))
{
- //rc = JsonConvert.DeserializeObject(_io.File.ReadAllText(_filePath), _jsonSettings);
var o = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(_io.File.ReadAllText(_filePath));
+ var schemaVer = DetectSchemaVersion(o);
+ if (schemaVer == SchemaMapper.PatchesSchemaVersionEnum.Unknown)
+ throw new DbPatchManagerException("Cannot detect patches.json schema version");
+
if (_io.File.Exists(_localFilePath))
{
var localO = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(_io.File.ReadAllText(_localFilePath));
@@ -110,11 +119,47 @@ from a in patches
return rc;
}
+ public SchemaMapper.PatchesSchemaVersionEnum DetectSchemaVersion(Newtonsoft.Json.Linq.JObject o)
+ {
+ //todo: write unit tests for this method and SchemaMapper class
+ var mapper = new SchemaMapper();
+ var rc = SchemaMapper.PatchesSchemaVersionEnum.Unknown;
+ var schemaVersionProperty = o.Property("schema");
+
+ if (schemaVersionProperty != null)
+ {
+ if (!string.IsNullOrWhiteSpace((string)schemaVersionProperty.Value))
+ {
+ string schemaStr = (string)schemaVersionProperty.Value;
+ rc = mapper.MapSchemaVersion(schemaStr);
+ }
+ }
+ else
+ {
+ // if no schemaVersion property then try to detect if v1 by checking other properties
+ var patchesProperty = o.Property("patches");
+
+ if (patchesProperty != null)
+ {
+ rc = SchemaMapper.PatchesSchemaVersionEnum.DbPatchV1;
+ }
+ }
+
+ return rc;
+ }
+
+ ///
+ /// Write DatabaseBuildConfiguration data to file path passed to constructor.
+ /// This method is used for all edits which currently include init and add patch.
+ /// The algorithm currently used writes the entire file each time. The algorithm decides whether to
+ /// write each property by checking first to see if the property exists in the local file. If it does
+ /// not exist in the local file then the property is written to the main file.
+ ///
+ ///
public void Write(DatabaseBuildConfiguration buildConfiguration)
{
JObject data;
- //todo: if local file exists, don't write values to patches.json if value exists in patches.local.json
if (_io.File.Exists(_localFilePath))
{
var localO = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.Linq.JToken.Parse(_io.File.ReadAllText(_localFilePath));
@@ -164,7 +209,6 @@ public void Write(DatabaseBuildConfiguration buildConfiguration)
}
else
{
- //string data = JsonConvert.SerializeObject(buildConfiguration, Formatting.Indented, _jsonSettings);
data = JObject.FromObject(new
{
DatabaseType = buildConfiguration.DatabaseType,
@@ -183,6 +227,9 @@ public void Write(DatabaseBuildConfiguration buildConfiguration)
});
}
+ // write all text creates the file if it doesn't exist
+ // but it also truncates the file before writing if it does exist
+ // so there will be no data left over from the original contents.
_io.File.WriteAllText(_filePath, data.ToString());
}
}
diff --git a/src/Ormico.DbPatchManager.Logic/OdbcDatabase.cs b/src/Ormico.DbPatchManager.Logic/OdbcDatabase.cs
index defe0f9..eeb6464 100644
--- a/src/Ormico.DbPatchManager.Logic/OdbcDatabase.cs
+++ b/src/Ormico.DbPatchManager.Logic/OdbcDatabase.cs
@@ -1,4 +1,5 @@
using Dapper;
+using Ormico.DbPatchManager.Common;
using System;
using System.Collections.Generic;
using System.Data.Odbc;
diff --git a/src/Ormico.DbPatchManager.Logic/Ormico.DbPatchManager.Logic.csproj b/src/Ormico.DbPatchManager.Logic/Ormico.DbPatchManager.Logic.csproj
index 77efa52..2282ce3 100644
--- a/src/Ormico.DbPatchManager.Logic/Ormico.DbPatchManager.Logic.csproj
+++ b/src/Ormico.DbPatchManager.Logic/Ormico.DbPatchManager.Logic.csproj
@@ -1,30 +1,40 @@
-
-
+
- netstandard2.0
- true
+ net8.0
+ True
true
- Copyright (c) 2020 Zack Moore
+ Copyright (c) 2023 Zack Moore
LICENSE
Ormico
Zack Moore
https://github.com/ormico/dbpatchmanager
Ormico DB Patch Manager Logic
- https://dbpatch.dev
+ https://dbpatch.dev/
+ 2.2.0
+ dbpatch-manager-profile.png
+ Logic Library for Database Change managment designed for multi-dev/multi-branch.
+ 2.1.2.0
-
-
-
-
-
+
+
+
+
+
-
+
+ True
+
+
+
True
-
+
+
-
-
+
+
+
+
\ No newline at end of file
diff --git a/src/Ormico.DbPatchManager.Logic/PatchManager.cs b/src/Ormico.DbPatchManager.Logic/PatchManager.cs
index d38d137..783c39b 100644
--- a/src/Ormico.DbPatchManager.Logic/PatchManager.cs
+++ b/src/Ormico.DbPatchManager.Logic/PatchManager.cs
@@ -1,4 +1,5 @@
-using System;
+using Ormico.DbPatchManager.Common;
+using System;
using System.Collections.Generic;
using System.IO.Abstractions;
using System.Linq;
diff --git a/src/Ormico.DbPatchManager.Logic/PluginManager.cs b/src/Ormico.DbPatchManager.Logic/PluginManager.cs
index 444e855..079734e 100644
--- a/src/Ormico.DbPatchManager.Logic/PluginManager.cs
+++ b/src/Ormico.DbPatchManager.Logic/PluginManager.cs
@@ -4,7 +4,7 @@
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
-
+using Ormico.DbPatchManager.Common;
namespace Ormico.DbPatchManager.Logic
{
@@ -14,15 +14,23 @@ public IDatabase LoadDatabasePlugin(string PluginType)
{
IDatabase rc = null;
if(string.Equals(PluginType, "TestDatabase", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(PluginType, typeof(TestDatabase).ToString(), StringComparison.OrdinalIgnoreCase))
+ string.Equals(PluginType, "test", StringComparison.OrdinalIgnoreCase) ||
+ string.Equals(PluginType, typeof(TestDatabase).ToString(), StringComparison.OrdinalIgnoreCase))
{
rc = new TestDatabase();
}
else if (string.Equals(PluginType, "OdbcDatabase", StringComparison.OrdinalIgnoreCase) ||
- string.Equals(PluginType, typeof(OdbcDatabase).ToString(), StringComparison.OrdinalIgnoreCase))
+ string.Equals(PluginType, "odbc", StringComparison.OrdinalIgnoreCase) ||
+ string.Equals(PluginType, typeof(OdbcDatabase).ToString(), StringComparison.OrdinalIgnoreCase))
{
rc = new OdbcDatabase();
}
+ else if (string.Equals(PluginType, "SqlDatabase", StringComparison.OrdinalIgnoreCase) ||
+ string.Equals(PluginType, "sqlserver", StringComparison.OrdinalIgnoreCase) ||
+ string.Equals(PluginType, typeof(SqlServer.SqlDatabase).ToString(), StringComparison.OrdinalIgnoreCase))
+ {
+ rc = new SqlServer.SqlDatabase();
+ }
else
{
string[] parts = PluginType.Split(',');
diff --git a/src/Ormico.DbPatchManager.Logic/SchemaMapper.cs b/src/Ormico.DbPatchManager.Logic/SchemaMapper.cs
new file mode 100644
index 0000000..2730e96
--- /dev/null
+++ b/src/Ormico.DbPatchManager.Logic/SchemaMapper.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ormico.DbPatchManager.Logic
+{
+ public class SchemaMapper
+ {
+ public SchemaMapper()
+ {
+ }
+
+ public PatchesSchemaVersionEnum MapSchemaVersion(string schemaName)
+ {
+ PatchesSchemaVersionEnum rc = PatchesSchemaVersionEnum.Unknown;
+ if (schemaNameToEnum.ContainsKey(schemaName))
+ rc = schemaNameToEnum[schemaName];
+ return rc;
+ }
+
+ Dictionary schemaNameToEnum = new Dictionary()
+ {
+ { PatchesSchemaVersionId.DbPatchV1, PatchesSchemaVersionEnum.DbPatchV1 }
+ };
+
+ public enum PatchesSchemaVersionEnum
+ {
+ Unknown = 0,
+ DbPatchV1 = 1
+ }
+
+ public class PatchesSchemaVersionId
+ {
+ public const string DbPatchV1 = "http://dbpatch.com/json-schema/ormico-dbpatch-v1.json";
+ }
+ }
+}
diff --git a/src/Ormico.DbPatchManager.Logic/TestDatabase.cs b/src/Ormico.DbPatchManager.Logic/TestDatabase.cs
index 0cc1c1d..6c19b0e 100644
--- a/src/Ormico.DbPatchManager.Logic/TestDatabase.cs
+++ b/src/Ormico.DbPatchManager.Logic/TestDatabase.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
+using Ormico.DbPatchManager.Common;
using System;
using System.Collections.Generic;
using System.Data.Common;
@@ -24,8 +25,14 @@ public void Connect(DatabaseOptions Options)
{
DbConnectionStringBuilder csb = new DbConnectionStringBuilder();
csb.ConnectionString = Options.ConnectionString;
- _fileName = csb["File"] as string;
-
+ if (csb.ContainsKey("File"))
+ {
+ _fileName = csb["File"] as string;
+ }
+ else
+ {
+ _fileName = "test.db";
+ }
Load();
}
diff --git a/src/Ormico.DbPatchManager.sln b/src/Ormico.DbPatchManager.sln
index 82396be..b393e08 100644
--- a/src/Ormico.DbPatchManager.sln
+++ b/src/Ormico.DbPatchManager.sln
@@ -1,4 +1,4 @@
-
+
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28803.352
@@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ormico.DbPatchManager.CLI",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ormico.DbPatchManager.Logic", "Ormico.DbPatchManager.Logic\Ormico.DbPatchManager.Logic.csproj", "{009D6D57-82CD-4617-A0B2-83F70D71E44E}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ormico.DbPatchManager.Logic.Tests", "Ormico.DbPatchManager.Logic.Tests\Ormico.DbPatchManager.Logic.Tests.csproj", "{59FD6996-4792-4F29-8F31-5873BC61F974}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ormico.DbPatchManager.Common", "Ormico.DbPatchManager.Common\Ormico.DbPatchManager.Common.csproj", "{EB7E7876-55E8-4B9D-82BA-387B90F363F6}"
+EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ormico.DbPatchManager.Logic.Tests", "Ormico.DbPatchManager.Logic.Tests\Ormico.DbPatchManager.Logic.Tests.csproj", "{6ECAE8E2-1FC5-4BFF-9C45-24C0215E35B6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -23,10 +25,14 @@ Global
{009D6D57-82CD-4617-A0B2-83F70D71E44E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{009D6D57-82CD-4617-A0B2-83F70D71E44E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{009D6D57-82CD-4617-A0B2-83F70D71E44E}.Release|Any CPU.Build.0 = Release|Any CPU
- {59FD6996-4792-4F29-8F31-5873BC61F974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {59FD6996-4792-4F29-8F31-5873BC61F974}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {59FD6996-4792-4F29-8F31-5873BC61F974}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {59FD6996-4792-4F29-8F31-5873BC61F974}.Release|Any CPU.Build.0 = Release|Any CPU
+ {EB7E7876-55E8-4B9D-82BA-387B90F363F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {EB7E7876-55E8-4B9D-82BA-387B90F363F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {EB7E7876-55E8-4B9D-82BA-387B90F363F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {EB7E7876-55E8-4B9D-82BA-387B90F363F6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6ECAE8E2-1FC5-4BFF-9C45-24C0215E35B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6ECAE8E2-1FC5-4BFF-9C45-24C0215E35B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6ECAE8E2-1FC5-4BFF-9C45-24C0215E35B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6ECAE8E2-1FC5-4BFF-9C45-24C0215E35B6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/install-dbpatch.sh b/src/install-dbpatch.sh
new file mode 100644
index 0000000..6274605
--- /dev/null
+++ b/src/install-dbpatch.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+# Copyright (c) Zack Moore MIT License. All rights reserved.
+# https://github.com/ormico/dbpatchmanager
+##################################################################
+#you can test using the docker dotnet container image
+#docker run -it --rm mcr.microsoft.com/dotnet/runtime /bin/bash
+##################################################################
+#dependencies
+#apt-get update && apt-get install -y wget unzip
+##################################################################
+{
+ INSTALL_DIR="/usr/local/lib/dbpatch"
+ BIN="/usr/local/bin/dbpatch"
+
+ if [ -h $BIN ]; then
+ echo "=> remove old symlink $BIN"
+ rm $BIN
+ fi
+
+ if [ -f $BIN ]; then
+ echo "=> there is a file at $BIN. install cannot proceed."
+ exit 1
+ fi
+
+ if [ -d $INSTALL_DIR ]; then
+ echo "=> dbpatch is already installed in $INSTALL_DIR, trying to update"
+ rm -r $INSTALL_DIR
+ fi
+
+ mkdir $INSTALL_DIR
+ # make release zip file dbpatch.zip . don't put version in filename. that way installer won't have to be updated for each version
+ #wget https://github.com/ormico/dbpatchmanager/releases/download/v2.1.1/dbpatch.zip -O "$INSTALL_DIR/dbpatch.zip"
+ wget https://github.com/ormico/dbpatchmanager/releases/latest/download/dbpatch.zip -O /usr/local/lib/dbpatch/dbpatch.zip
+ unzip "$INSTALL_DIR/dbpatch.zip" -d $INSTALL_DIR
+ chmod +x "$INSTALL_DIR/dbpatch"
+ rm "$INSTALL_DIR/dbpatch.zip"
+
+ # make sure file is in linux format so you don't need this dependency
+ #dos2unix /usr/local/lib/dbpatch/dbpatch
+ ln -s "$INSTALL_DIR/dbpatch" $BIN
+}