Giter VIP home page Giter VIP logo

dbup-mysql's Introduction

GitHub Workflow Status (branch) NuGet NuGet Prerelease

DbUp MySql support

DbUp is a .NET library that helps you to deploy changes to SQL Server databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date.

Getting Help

To learn more about DbUp check out the documentation

Please only log issue related to MySql support in this repo. For cross cutting issues, please use our main issue list.

Contributing

See the readme in our main repo for how to get started and contribute.

dbup-mysql's People

Contributors

ajeckmans avatar droyad avatar epenet avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

dbup-mysql's Issues

Switch from MySql.Data to MySqlConnector

Is there an existing issue for this?

  • I have searched the existing open and closed issues

Description

MySql.Data is no longer compatible with MariaDB and fails when using MariaDB version 10+. Research indicates that switching from MySql.Data to MySqlConnector will resolve this.

What is the impact?

dbup using the dbup-mysql reference fails to execute against an MariaDB version 10+.

dbup-mysql not handling 'delimiter' correctly

When using dbup v4 if a statement contains the word 'delimiter' then the word and the following word are dropped from the statement. This causes a problem if the word occurs in a string that's being inserted or updated for example. See the unit test below. This was not an issue in v3.3.5.

Expecting 'Some text with delimiter in it' to be written to the database but what actually gets written is 'Some text with it'.

        [Fact]
        public void DoesNotParseOutTheWordDelimiterWhenItsInAString()
        {
            var multiCommand = "USE `test`;";
            multiCommand += "CREATE TABLE IF NOT EXISTS 'FOO';";
            multiCommand += Environment.NewLine;
            multiCommand += "DELIMITER $$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE 'ZIP'$$";
            multiCommand += Environment.NewLine;
            multiCommand += "CREATE TABLE IF NOT EXISTS 'BAR';";
            multiCommand += Environment.NewLine;
            multiCommand += "INSERT INTO mytable(description) VALUES ('Some text with delimiter in it');";

            var connectionManager = new MySqlConnectionManager("connectionstring");
            var result = connectionManager.SplitScriptIntoCommands(multiCommand);

            var enumerable = result as string[] ?? result.ToArray();
            enumerable.Length.ShouldBe(4);
            enumerable[0].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[1].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[2].IndexOf("DELIMITER", StringComparison.Ordinal).ShouldBe(-1);
            enumerable[3].IndexOf("DELIMITER", StringComparison.OrdinalIgnoreCase).ShouldBeGreaterThan(-1);
        }

Upgrade schema is failing to upgrade a new database.

Fails to retrieve the schema name from the connection string when there is an extra space in the connection string - From Azure Portal the Connection strings have an extra space among the parts.

Potential fix is in the foreach loop where the token is trimmed any extra spaces.

File: src\dbup-mysql\MySqlExtensions.cs

public static class MySqlExtensions
{
    /// <summary>
    /// Creates an upgrader for MySql databases.
    /// </summary>
    /// <param name="supported">Fluent helper type.</param>
    /// <param name="connectionString">MySql database connection string.</param>
    /// <returns>
    /// A builder for a database upgrader designed for MySql databases.
    /// </returns>
    public static UpgradeEngineBuilder MySqlDatabase(this SupportedDatabases supported, string connectionString)
    {
        foreach (var pair in connectionString.Split(';').Select(s => s.Split('=')).Where(pair => pair.Length == 2).Where(pair => pair[0].Trim().ToLower() == "database"))
        {
            return MySqlDatabase(new MySqlConnectionManager(connectionString), pair[1]);
        }

        return MySqlDatabase(new MySqlConnectionManager(connectionString));
    }

Creating a StoreProc Syntax Error

Afternoon,

I'm trying to use DbUp to create a new Store Proc and I'm getting a syntax error when execute PerformUpgrade... My script works directly on a query window on the MySQL database.

here is the query

DROP PROCEDURE IF EXISTS My_StoreProc;

CREATE PROCEDURE My_StoreProc;(strEmail VARCHAR(255))

BEGIN
SELECT id FROM table WHERE email = strEmail
ORDER BY id DESC limit 1;
END;

Here is the error:
Script block number: 1; Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
at DbUp.Support.ScriptExecutor.ExecuteAndLogOutput(IDbCommand command)
at DbUp.Support.ScriptExecutor.<>c__DisplayClass18_2.b__1()
at DbUp.MySql.MySqlScriptExecutor.ExecuteCommandsWithinExceptionHandler(Int32 index, SqlScript script, Action executeCommand)

Any suggestions, is there a work arround, is this a know bug?

Faced issue in executing script during update row

Hi, I'm not able to execute the script through DbUp during one of the update rows in script. However it's executed fine from mysql-cli.

Here is the update command within sql script:

UPDATE `block` SET `name`='from enum import Enum\nimport json\n\nhost_url = \"http://abcURL:80/\"\nservice_url = \"http://e..............';

Here is the error I got:

Checking whether journal table exists..
MySql exception has occured in script: 'Script.sql'
Script block number: 1; MySql error code: 0; Number 1064; Message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''from enum import Enum\nimport json\n\nhost_url = \"http://abcURL:80/\"\nse' at line 1
MySql.Data.MySqlClient.MySqlException (0x80004005): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''from enum import Enum\nimport json\n\nhost_url = \"http://abcURL:80/\"\nse' at line 1
   at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affectedRows, Int64& insertedId)
   at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
   at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at DbUp.Support.ScriptExecutor.ExecuteNonQuery(IDbCommand command)
   at DbUp.Support.ScriptExecutor.<>c__DisplayClass18_2.<Execute>b__1()
   at DbUp.MySql.MySqlScriptExecutor.ExecuteCommandsWithinExceptionHandler(Int32 index, SqlScript script, Action executeCommand)

dbUp fails when a combination of "\'" & ";" is in the script

The following script is failing when running in mySQL.

DROP TABLE IF EXISTS test;

CREATE TABLE test (
id int DEFAULT NULL,
message varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*!40000 ALTER TABLE test DISABLE KEYS /;
INSERT INTO test VALUES
(1,'CCP\'s valuation') ;
INSERT INTO test VALUES
(2,'UTI = ;') ;
/
!40000 ALTER TABLE test ENABLE KEYS */;

The following script runs successfully. Only change is removing the "\'" and having "CCPs" instead of "CCP\'s".
DROP TABLE IF EXISTS test;

CREATE TABLE test (
id int DEFAULT NULL,
message varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

/*!40000 ALTER TABLE test DISABLE KEYS /;
INSERT INTO test VALUES
(1,'CCPs valuation') ;
INSERT INTO test VALUES
(2,'UTI = ;') ;
/
!40000 ALTER TABLE test ENABLE KEYS */;

The error of the failing script is:
error.txt

this is some kind of relation between the quoted "\'" and the ";"

Appreciate if you can run this script and see it is failing since it is 3rd time I am opening this bug and getting irrelevant answers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.