SQLMigrationByQuery 1.0.0.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package SQLMigrationByQuery --version 1.0.0.12                
NuGet\Install-Package SQLMigrationByQuery -Version 1.0.0.12                
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="SQLMigrationByQuery" Version="1.0.0.12" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SQLMigrationByQuery --version 1.0.0.12                
#r "nuget: SQLMigrationByQuery, 1.0.0.12"                
#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 SQLMigrationByQuery as a Cake Addin
#addin nuget:?package=SQLMigrationByQuery&version=1.0.0.12

// Install SQLMigrationByQuery as a Cake Tool
#tool nuget:?package=SQLMigrationByQuery&version=1.0.0.12                

SQLMigrationByQuery

This library is SQL database schema version control, This library will execute SQL schema migration query list in .net projects. It's useful for software developers who don't want to use something like Entinty Framework code first and they prefer write their schema migration query by themselves.

Features

SQLMigrationByQuery is .net NuGet Package which control your database schema migration querys, This library will execute all .sql file which you mark them in you main project. After execute any query in your query list a log will save in database.

Version Log

ver 1.0.0.12 :

  • .NetStandard 2 & .Net Framework 4 support

ver 1.0.0.11 :

  • Extand timeout to 600 sec

ver 1.0.0.10 :

  • Extend MigrationName and MigrationProject string length
  • Support GO in .sql file
  • Support replace text in query at execution time

How to use?

  1. Add SQLMigrationByQuery NuGet Package to your project.
  2. Create a .sql file in your project.
  3. Make sure your .sql files build action is set to "Embedded Resource".
  4. Set any 'MigrationMark' you want in .sql file name, For example "Migration-2020081801-FirstInit.sql", The word "Migration-" is 'MigrationMark'.
  5. Call the fuction below in any place you want execute your migration query list.

You can always see the full sample of usage in WinAppTester project.

SQLMigrationByQuery.requestMigration objRequest = new SQLMigrationByQuery.requestMigration();
objRequest.ConnectionString = "YourConnectionString";
objRequest.CallerProjectName = "YourProjectName";
objRequest.MigrationMark = "Migration-";
objRequest.ReplaceTextInQuery = false;
objRequest.ReplaceTextSource = "";
objRequest.ReplaceTextTarget = "";
SQLMigrationByQuery.resultMigration objResult = SQLMigrationByQuery.helperMigration.getApplyMigration(objRequest);
if (objResult.Success == true)
{
    MessageBox.Show("Migration was successful");
}
else
{
    MessageBox.Show(objResult.ResultMessage);
}

If objResult.Success be TRUE it means all query all execute successfully, Otherwise you can find the error in objResult.ResultMessage.

You can check the migration result in database by below query

SELECT * FROM dbo.___DatabaseMigration

The .sql sample :

--@strMigrationDesc=Add address and mobile for user table
ALTER TABLE dbo.tblUser ADD [strMobile] VARCHAR(11) NULL
GO
ALTER TABLE dbo.tblUser ADD [strAddress] NVARCHAR(300) NULL
GO

Set your migration description front of --@strMigrationDesc= in your .sql file.

Tips

  1. If migration query execute successfully it means that query will never execute again.
  2. Migration .sql files will execute by STRING order so make sure their names are ok.
  3. If any query fail the process will stop and return FALSE and the error in ResultMessage property.
  4. You can use GO in your .sql file now (version >= 1.0.0.10).
  5. All command in same .sql file will execute in a transaction, It will rollback if of the batchs in query fail.
  6. The .sql file name should be unique otherwise they second query with same name will never execute.
  7. The migration description exists in your .sql files will be save in migration log (dbo.___DatabaseMigration table)
  8. Make sure your .sql files build action is set to "Embedded Resource".
  9. The caller project name ("YourProjectName") is useful when you want call migration library on more than one project on same database.
  10. If you don't need replace text in your querys just ignore ReplaceTextInQuery, ReplaceTextSource and ReplaceTextTarget property and don't fill them.

Warning

You shouldn't change CallerProjectName in future, Otherwise all query will execute again with new project name. You shouldn't rename your .sql files otherwise that new .sql will execute again.

Author message

I write this library for my personal use but i think it could be useful to other software developers which they don't want to use Entity Framework code first.

If you think any place need an improvement please let me know by pull reuqest.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net40 is compatible.  net403 was computed.  net45 was computed.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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.0.0.16 471 10/26/2022
1.0.0.15 379 12/26/2021
1.0.0.14 369 9/7/2021
1.0.0.13 404 3/8/2021
1.0.0.12 404 2/23/2021
1.0.0.11 382 2/22/2021
1.0.0.10 425 1/22/2021
1.0.0.9 606 8/30/2020

.netstandard2 & .net framework 4 support