Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(driver): Resolve Exception during PerformUpgrade using LogScriptOutput #577 #5

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.Data.Sqlite;

namespace SQLiteSampleApplication
{
Expand Down Expand Up @@ -55,7 +56,7 @@ static void TemporaryFileDb()

static void PermanentFileDb()
{
Microsoft.Data.Sqlite.SqliteConnection connection = new("Data Source=dbup.db");
SqliteConnection connection = new("Data Source=dbup.db");

using (var database = new DbUp.SQLite.Helpers.SharedConnection(connection))
{
Expand Down
30 changes: 26 additions & 4 deletions src/Tests/SQLiteSupportTests.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using Microsoft.Data.Sqlite;
using Shouldly;
using Shouldly;
using Xunit;

namespace DbUp.SQLite.Tests
{
public class SQLiteSupportTests
{
static readonly string dbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db");
static readonly string DbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db");

[Fact]
public void CanUseSQLite()
{
var connectionString = $"Data Source={dbFilePath}";
var connectionString = $"Data Source={DbFilePath}";

var upgrader = DeployChanges.To
.SQLiteDatabase(connectionString)
Expand All @@ -23,5 +22,28 @@ public void CanUseSQLite()
result.Error.ShouldBe(null);
result.Successful.ShouldBe(true);
}

/// <summary>
/// Test for https://github.com/DbUp/dbup-sqlite/issues/2
/// </summary>
[Fact]
public void DoesNotExhibitSafeHandleError()
{
var connectionString = "Data source=:memory:";

var upgrader =
DeployChanges.To
.SQLiteDatabase(connectionString)
.WithScript("Script001", @"
create table test (
contact_id INTEGER PRIMARY KEY
);
")
.LogScriptOutput()
.LogToConsole()
.Build();
var result = upgrader.PerformUpgrade();
result.Successful.ShouldBeTrue();
}
}
}
2 changes: 2 additions & 0 deletions src/dbup-sqlite/Helpers/InMemorySQLiteDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public InMemorySQLiteDatabase()
{
DataSource = ":memory:",
DefaultTimeout = 5,
Mode = SqliteOpenMode.Memory,
ConnectionString = "PRAGMA encoding='UTF-16'; PRAGMA journal_mode='MEMORY';"
Comment on lines +26 to +27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed these in my conversion. Don't know enough about SQLite to judge whether this is good/bad, but keeping it.

};
ConnectionString = connectionStringBuilder.ToString();

Expand Down
Loading