This repository has been archived by the owner on Jul 25, 2024. It is now read-only.
generated from DbUp/dbup-provider-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copied from main project and duplicated code from non-mono sqllite pr…
…oject
- Loading branch information
Showing
20 changed files
with
743 additions
and
9 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyBasicSupport.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
DB Operation: Open connection | ||
Info: Beginning database upgrade | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Journal table does not exist | ||
Info: Executing Database Server script 'Script0001.sql' | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Creating the [SchemaVersions] table | ||
DB Operation: Execute non query command: CREATE TABLE [SchemaVersions] ( | ||
SchemaVersionID INTEGER CONSTRAINT [PK_SchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
ScriptName TEXT NOT NULL, | ||
Applied DATETIME NOT NULL | ||
) | ||
DB Operation: Dispose command | ||
Info: The [SchemaVersions] table has been created | ||
DB Operation: Execute non query command: script1contents | ||
DB Operation: Dispose command | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: applied=<date> | ||
DB Operation: Execute non query command: insert into [SchemaVersions] (ScriptName, Applied) values (@scriptName, @applied) | ||
DB Operation: Dispose command | ||
Info: Upgrade successful | ||
DB Operation: Dispose connection |
28 changes: 28 additions & 0 deletions
28
src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyJournalCreationIfNameChanged.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
DB Operation: Open connection | ||
Info: Beginning database upgrade | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Journal table does not exist | ||
Info: Executing Database Server script 'Script0001.sql' | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Creating the [TestSchemaVersions] table | ||
DB Operation: Execute non query command: CREATE TABLE [TestSchemaVersions] ( | ||
SchemaVersionID INTEGER CONSTRAINT [PK_TestSchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
ScriptName TEXT NOT NULL, | ||
Applied DATETIME NOT NULL | ||
) | ||
DB Operation: Dispose command | ||
Info: The [TestSchemaVersions] table has been created | ||
DB Operation: Execute non query command: script1contents | ||
DB Operation: Dispose command | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: applied=<date> | ||
DB Operation: Execute non query command: insert into [TestSchemaVersions] (ScriptName, Applied) values (@scriptName, @applied) | ||
DB Operation: Dispose command | ||
Info: Upgrade successful | ||
DB Operation: Dispose connection |
28 changes: 28 additions & 0 deletions
28
src/Tests/ApprovalFiles/DatabaseSupportTests.VerifyVariableSubstitutions.verified.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
DB Operation: Open connection | ||
Info: Beginning database upgrade | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Journal table does not exist | ||
Info: Executing Database Server script 'Script0001.sql' | ||
Info: Checking whether journal table exists.. | ||
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions' | ||
DB Operation: Dispose command | ||
Info: Creating the [SchemaVersions] table | ||
DB Operation: Execute non query command: CREATE TABLE [SchemaVersions] ( | ||
SchemaVersionID INTEGER CONSTRAINT [PK_SchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
ScriptName TEXT NOT NULL, | ||
Applied DATETIME NOT NULL | ||
) | ||
DB Operation: Dispose command | ||
Info: The [SchemaVersions] table has been created | ||
DB Operation: Execute non query command: print SubstitutedValue | ||
DB Operation: Dispose command | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql | ||
DB Operation: Create parameter | ||
Info: DB Operation: Add parameter to command: applied=<date> | ||
DB Operation: Execute non query command: insert into [SchemaVersions] (ScriptName, Applied) values (@scriptName, @applied) | ||
DB Operation: Dispose command | ||
Info: Upgrade successful | ||
DB Operation: Dispose connection |
77 changes: 77 additions & 0 deletions
77
src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
[assembly: System.CLSCompliantAttribute(true)] | ||
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)] | ||
[assembly: System.Runtime.InteropServices.GuidAttribute("bce32c14-27e3-4e0d-bc1f-ec9ccb128f00")] | ||
|
||
public static class SQLiteExtensions | ||
{ | ||
public static DbUp.Builder.UpgradeEngineBuilder JournalToSQLiteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { } | ||
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { } | ||
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } | ||
} | ||
namespace DbUp.SQLite | ||
{ | ||
public class SQLiteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager | ||
{ | ||
public SQLiteConnectionManager(string connectionString) { } | ||
public SQLiteConnectionManager(DbUp.SQLite.Helpers.SharedConnection sharedConnection) { } | ||
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { } | ||
} | ||
public class SQLiteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser | ||
{ | ||
public SQLiteObjectParser() { } | ||
} | ||
public class SQLitePreprocessor : DbUp.Engine.IScriptPreprocessor | ||
{ | ||
public SQLitePreprocessor() { } | ||
public string Process(string contents) { } | ||
} | ||
public class SQLiteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor | ||
{ | ||
public SQLiteScriptExecutor(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManagerFactory, System.Func<DbUp.Engine.Output.IUpgradeLog> log, string schema, System.Func<bool> variablesEnabled, System.Collections.Generic.IEnumerable<DbUp.Engine.IScriptPreprocessor> scriptPreprocessors, System.Func<DbUp.Engine.IJournal> journalFactory) { } | ||
protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { } | ||
protected override string GetVerifySchemaSql(string schema) { } | ||
} | ||
public class SQLiteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal | ||
{ | ||
public SQLiteTableJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string table) { } | ||
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { } | ||
protected override string DoesTableExistSql() { } | ||
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { } | ||
protected override string GetJournalEntriesSql() { } | ||
} | ||
} | ||
namespace DbUp.SQLite.Helpers | ||
{ | ||
public class InMemorySQLiteDatabase : System.IDisposable | ||
{ | ||
public InMemorySQLiteDatabase() { } | ||
public string ConnectionString { get; set; } | ||
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } | ||
public void Dispose() { } | ||
public DbUp.Engine.Transactions.IConnectionManager GetConnectionManager() { } | ||
} | ||
public class SharedConnection : System.Data.IDbConnection, System.IDisposable | ||
{ | ||
public SharedConnection(System.Data.IDbConnection dbConnection) { } | ||
public string ConnectionString { get; set; } | ||
public int ConnectionTimeout { get; } | ||
public string Database { get; } | ||
public System.Data.ConnectionState State { get; } | ||
public System.Data.IDbTransaction BeginTransaction() { } | ||
public System.Data.IDbTransaction BeginTransaction(System.Data.IsolationLevel il) { } | ||
public void ChangeDatabase(string databaseName) { } | ||
public void Close() { } | ||
public System.Data.IDbCommand CreateCommand() { } | ||
public void Dispose() { } | ||
public void DoClose() { } | ||
public void Open() { } | ||
} | ||
public class TemporarySQLiteDatabase : System.IDisposable | ||
{ | ||
public TemporarySQLiteDatabase(string name) { } | ||
public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; } | ||
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; } | ||
public void Create() { } | ||
public void Dispose() { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using DbUp.Builder; | ||
using DbUp.Tests.Common; | ||
|
||
namespace DbUp.SQLite.Tests; | ||
|
||
public class DatabaseSupportTests : DatabaseSupportTestsBase | ||
{ | ||
public DatabaseSupportTests() : base() | ||
{ | ||
} | ||
|
||
protected override UpgradeEngineBuilder DeployTo(SupportedDatabases to) | ||
=> to.SQLiteDatabase(""); | ||
|
||
protected override UpgradeEngineBuilder AddCustomNamedJournalToBuilder(UpgradeEngineBuilder builder, string schema, string tableName) | ||
=> builder.JournalTo( | ||
(connectionManagerFactory, logFactory) | ||
=> new SQLiteTableJournal(connectionManagerFactory, logFactory, tableName) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using DbUp.Tests.Common; | ||
|
||
namespace DbUp.SQLite.Tests; | ||
|
||
public class NoPublicApiChanges : NoPublicApiChangesBase | ||
{ | ||
public NoPublicApiChanges() | ||
: base(typeof(SQLiteExtensions).Assembly) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.IO; | ||
using Mono.Data.Sqlite; | ||
using Xunit; | ||
|
||
namespace DbUp.SQLite.Tests | ||
{ | ||
public class SQLiteSupportTests | ||
{ | ||
static readonly string dbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db"); | ||
|
||
[Fact] | ||
public void CanUseSQLite() | ||
{ | ||
var connectionString = string.Format("Data Source={0}; Version=3;", dbFilePath); | ||
|
||
if (!File.Exists(dbFilePath)) | ||
{ | ||
SqliteConnection.CreateFile(dbFilePath); | ||
} | ||
|
||
var upgrader = DeployChanges.To | ||
.SQLiteDatabase(connectionString) | ||
.WithScript("Script0001", "CREATE TABLE IF NOT EXISTS Foo (Id int)") | ||
.Build(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using DbUp.Engine; | ||
using DbUp.Engine.Output; | ||
using DbUp.Engine.Transactions; | ||
using DbUp.Tests.Common; | ||
using Mono.Data.Sqlite; | ||
using NSubstitute; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace DbUp.SQLite.Tests | ||
{ | ||
public class SQLiteTableJournalTests | ||
{ | ||
[Fact] | ||
public void dbversion_is_zero_when_journal_table_not_exist() | ||
{ | ||
// Given | ||
var dbConnection = Substitute.For<IDbConnection>(); | ||
var command = Substitute.For<IDbCommand>(); | ||
dbConnection.CreateCommand().Returns(command); | ||
var connectionManager = Substitute.For<IConnectionManager>(); | ||
command.ExecuteScalar().Returns(x => { throw new SqliteException("table not found"); }); | ||
var consoleUpgradeLog = new ConsoleUpgradeLog(); | ||
var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); | ||
|
||
// When | ||
var scripts = journal.GetExecutedScripts(); | ||
|
||
// Expect | ||
command.DidNotReceive().ExecuteReader(); | ||
scripts.ShouldBeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void creates_a_new_journal_table_when_not_exist() | ||
{ | ||
// Given | ||
var dbConnection = Substitute.For<IDbConnection>(); | ||
var connectionManager = new TestConnectionManager(dbConnection); | ||
connectionManager.OperationStarting(new ConsoleUpgradeLog(), new List<SqlScript>()); | ||
|
||
var command = Substitute.For<IDbCommand>(); | ||
var param1 = Substitute.For<IDbDataParameter>(); | ||
var param2 = Substitute.For<IDbDataParameter>(); | ||
dbConnection.CreateCommand().Returns(command); | ||
command.CreateParameter().Returns(param1, param2); | ||
command.ExecuteScalar().Returns(x => 0); | ||
var consoleUpgradeLog = new ConsoleUpgradeLog(); | ||
var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions"); | ||
|
||
// When | ||
journal.StoreExecutedScript(new SqlScript("test", "select 1"), () => command); | ||
|
||
// Expect | ||
command.Received(2).CreateParameter(); | ||
param1.ParameterName.ShouldBe("scriptName"); | ||
param2.ParameterName.ShouldBe("applied"); | ||
command.Received().ExecuteNonQuery(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using DbUp.Engine.Transactions; | ||
using DbUp.Helpers; | ||
using Mono.Data.Sqlite; | ||
|
||
namespace DbUp.SQLite.Helpers | ||
{ | ||
/// <summary> | ||
/// Used to create in-memory SQLite database that is deleted at the end of a test. | ||
/// </summary> | ||
public class InMemorySQLiteDatabase : IDisposable | ||
{ | ||
readonly SQLiteConnectionManager connectionManager; | ||
readonly SqliteConnection sharedConnection; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="InMemorySQLiteDatabase"/> class. | ||
/// </summary> | ||
public InMemorySQLiteDatabase() | ||
{ | ||
var connectionStringBuilder = new SqliteConnectionStringBuilder() | ||
{ | ||
DataSource = ":memory:", | ||
Version = 3, | ||
DefaultTimeout = 5, | ||
JournalMode = SQLiteJournalModeEnum.Off, | ||
UseUTF16Encoding = true | ||
}; | ||
ConnectionString = connectionStringBuilder.ToString(); | ||
|
||
connectionManager = new SQLiteConnectionManager(connectionStringBuilder.ConnectionString); | ||
sharedConnection = new SqliteConnection(connectionStringBuilder.ConnectionString); | ||
sharedConnection.Open(); | ||
SqlRunner = new AdHocSqlRunner(() => sharedConnection.CreateCommand(), new SQLiteObjectParser(), null, () => true); | ||
} | ||
|
||
public string ConnectionString { get; set; } | ||
|
||
/// <summary> | ||
/// Gets the connection factory of in-memory database. | ||
/// </summary> | ||
public IConnectionManager GetConnectionManager() => connectionManager; | ||
|
||
/// <summary> | ||
/// An adhoc sql runner against the in-memory database | ||
/// </summary> | ||
public AdHocSqlRunner SqlRunner { get; } | ||
|
||
/// <summary> | ||
/// Remove the database from memory. | ||
/// </summary> | ||
public void Dispose() => sharedConnection.Dispose(); | ||
} | ||
} |
Oops, something went wrong.