Skip to content
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
6 changes: 3 additions & 3 deletions src/Sample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public static class Program
{
static void Main()
{
InMemoryDb();
TemporaryFileDb();
//InMemoryDb();
//TemporaryFileDb();
PermanentFileDb();
}

Expand Down Expand Up @@ -56,7 +56,7 @@ static void TemporaryFileDb()

static void PermanentFileDb()
{
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
5 changes: 4 additions & 1 deletion src/dbup-sqlite/Helpers/InMemorySqliteDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using DbUp.Engine.Transactions;
using DbUp.Helpers;
using Microsoft.Data.Sqlite;
Expand Down Expand Up @@ -33,6 +33,9 @@ public InMemorySqliteDatabase()
SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SqliteObjectParser(), null, () => true);
}

/// <summary>
/// Gets or sets the connection string for the in-memory database.
/// </summary>
public string ConnectionString { get; set; }

/// <summary>
Expand Down
16 changes: 15 additions & 1 deletion src/dbup-sqlite/Helpers/SharedConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Data;

namespace DbUp.Sqlite.Helpers
Expand Down Expand Up @@ -30,36 +30,50 @@ public SharedConnection(IDbConnection dbConnection)
connection.Open();
}

/// <inheritdoc/>
public IDbTransaction BeginTransaction(IsolationLevel il) => connection.BeginTransaction(il);

/// <inheritdoc/>
public IDbTransaction BeginTransaction() => connection.BeginTransaction();

/// <inheritdoc/>
public void ChangeDatabase(string databaseName) => connection.ChangeDatabase(databaseName);

/// <inheritdoc/>
public void Close() { } // shared underlying connection is not closed

/// <inheritdoc/>
public string ConnectionString
{
get => connection.ConnectionString;
set => connection.ConnectionString = value;
}

/// <inheritdoc/>
public int ConnectionTimeout => connection.ConnectionTimeout;

/// <inheritdoc/>
public IDbCommand CreateCommand() => connection.CreateCommand();

/// <inheritdoc/>
public string Database => connection.Database;

/// <inheritdoc/>
public void Open()
{
if (connection.State == ConnectionState.Closed)
connection.Open();
}

/// <inheritdoc/>
public ConnectionState State => connection.State;

/// <inheritdoc/>
public void Dispose() { } // shared underlying connection is not disposed

/// <summary>
/// Closes the connection if it was opened by this wrapper.
/// </summary>
public void DoClose()
{
// if shared underlying connection is opened by this object
Expand Down
5 changes: 4 additions & 1 deletion src/dbup-sqlite/Helpers/TemporarySqliteDatabase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using DbUp.Helpers;
using Microsoft.Data.Sqlite;
Expand Down Expand Up @@ -39,6 +39,9 @@ public TemporarySqliteDatabase(string name)
/// </summary>
public AdHocSqlRunner SqlRunner { get; }

/// <summary>
/// Gets the shared connection used by this temporary database.
/// </summary>
public SharedConnection SharedConnection { get; }

/// <summary>
Expand Down
6 changes: 2 additions & 4 deletions src/dbup-sqlite/SqliteConnectionManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using DbUp.Engine.Transactions;
Expand Down Expand Up @@ -26,9 +26,7 @@ public SqliteConnectionManager(SharedConnection sharedConnection) : base(l => sh
{
}

/// <summary>
/// Sqlite statements separator is ; (see http://www.sqlite.org/lang.html)
/// </summary>
/// <inheritdoc/>
public override IEnumerable<string> SplitScriptIntoCommands(string scriptContents)
{
var scriptStatements =
Expand Down
3 changes: 2 additions & 1 deletion src/dbup-sqlite/SqliteExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DbUp.Builder;
using DbUp.Builder;
using DbUp.Sqlite;
using DbUp.Sqlite.Helpers;

Expand Down Expand Up @@ -53,6 +53,7 @@ public static UpgradeEngineBuilder SqliteDatabase(this SupportedDatabases suppor
/// <summary>
/// Tracks the list of executed scripts in a custom SQLite table.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="table">The name of the table used to store the list of executed scripts.</param>
/// <returns>The <see cref="UpgradeEngineBuilder"/> used to set the journal table name.</returns>
public static UpgradeEngineBuilder JournalToSqliteTable(this UpgradeEngineBuilder builder, string table)
Expand Down
5 changes: 4 additions & 1 deletion src/dbup-sqlite/SqliteObjectParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using DbUp.Support;
using DbUp.Support;

namespace DbUp.Sqlite
{
Expand All @@ -7,6 +7,9 @@ namespace DbUp.Sqlite
/// </summary>
public class SqliteObjectParser : SqlObjectParser
{
/// <summary>
/// Initializes a new instance of the <see cref="SqliteObjectParser"/> class.
/// </summary>
public SqliteObjectParser()
: base("[", "]")
{
Expand Down
4 changes: 3 additions & 1 deletion src/dbup-sqlite/SqliteScriptExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using DbUp.Engine;
using DbUp.Engine.Output;
Expand Down Expand Up @@ -28,11 +28,13 @@ public SqliteScriptExecutor(Func<IConnectionManager> connectionManagerFactory, F
{
}

/// <inheritdoc/>
protected override string GetVerifySchemaSql(string schema)
{
throw new NotSupportedException();
}

/// <inheritdoc/>
protected override void ExecuteCommandsWithinExceptionHandler(int index, SqlScript script, Action executeCommand)
{
try
Expand Down
9 changes: 8 additions & 1 deletion src/dbup-sqlite/SqliteTableJournal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using DbUp.Engine;
using DbUp.Engine.Output;
using DbUp.Engine.Transactions;
Expand All @@ -15,20 +15,26 @@ public class SqliteTableJournal : TableJournal
/// <summary>
/// Initializes a new instance of the <see cref="SqliteTableJournal"/> class.
/// </summary>
/// <param name="connectionManager">The connection manager.</param>
/// <param name="logger">The log.</param>
/// <param name="table">The table name.</param>
public SqliteTableJournal(Func<IConnectionManager> connectionManager, Func<IUpgradeLog> logger, string table) :
base(connectionManager, logger, new SqliteObjectParser(), null, table)
{ }

/// <inheritdoc/>
protected override string GetInsertJournalEntrySql(string @scriptName, string @applied)
{
return $"insert into {FqSchemaTableName} (ScriptName, Applied) values ({@scriptName}, {@applied})";
}

/// <inheritdoc/>
protected override string GetJournalEntriesSql()
{
return $"select [ScriptName] from {FqSchemaTableName} order by [ScriptName]";
}

/// <inheritdoc/>
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName)
{
return
Expand All @@ -39,6 +45,7 @@ Applied DATETIME NOT NULL
)";
}

/// <inheritdoc/>
protected override string DoesTableExistSql()
{
return $"SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = '{UnquotedSchemaTableName}'";
Expand Down
3 changes: 2 additions & 1 deletion src/dbup-sqlite/dbup-sqlite.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>DbUp makes it easy to deploy and upgrade SQL Server databases. This package adds SQLite support.</Description>
Expand All @@ -14,6 +14,7 @@
<SignAssembly>true</SignAssembly>
<RepositoryUrl>https://github.com/DbUp/dbup-sqlite.git</RepositoryUrl>
<PackageIcon>dbup-icon.png</PackageIcon>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(CI)' == 'true'">
Expand Down