Skip to content

Commit 97bb48e

Browse files
committed
Copied from main project
1 parent 71cb5ec commit 97bb48e

20 files changed

+897
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
DB Operation: Open connection
2+
Info: Beginning database upgrade
3+
Info: Checking whether journal table exists..
4+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions'
5+
DB Operation: Dispose command
6+
Info: Journal table does not exist
7+
Info: Executing Database Server script 'Script0001.sql'
8+
Info: Checking whether journal table exists..
9+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions'
10+
DB Operation: Dispose command
11+
Info: Creating the [SchemaVersions] table
12+
DB Operation: Execute non query command: CREATE TABLE [SchemaVersions] (
13+
SchemaVersionID INTEGER CONSTRAINT [PK_SchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL,
14+
ScriptName TEXT NOT NULL,
15+
Applied DATETIME NOT NULL
16+
)
17+
DB Operation: Dispose command
18+
Info: The [SchemaVersions] table has been created
19+
DB Operation: Execute non query command: script1contents
20+
DB Operation: Dispose command
21+
DB Operation: Create parameter
22+
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql
23+
DB Operation: Create parameter
24+
Info: DB Operation: Add parameter to command: applied=<date>
25+
DB Operation: Execute non query command: insert into [SchemaVersions] (ScriptName, Applied) values (@scriptName, @applied)
26+
DB Operation: Dispose command
27+
Info: Upgrade successful
28+
DB Operation: Dispose connection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
DB Operation: Open connection
2+
Info: Beginning database upgrade
3+
Info: Checking whether journal table exists..
4+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions'
5+
DB Operation: Dispose command
6+
Info: Journal table does not exist
7+
Info: Executing Database Server script 'Script0001.sql'
8+
Info: Checking whether journal table exists..
9+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'TestSchemaVersions'
10+
DB Operation: Dispose command
11+
Info: Creating the [TestSchemaVersions] table
12+
DB Operation: Execute non query command: CREATE TABLE [TestSchemaVersions] (
13+
SchemaVersionID INTEGER CONSTRAINT [PK_TestSchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL,
14+
ScriptName TEXT NOT NULL,
15+
Applied DATETIME NOT NULL
16+
)
17+
DB Operation: Dispose command
18+
Info: The [TestSchemaVersions] table has been created
19+
DB Operation: Execute non query command: script1contents
20+
DB Operation: Dispose command
21+
DB Operation: Create parameter
22+
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql
23+
DB Operation: Create parameter
24+
Info: DB Operation: Add parameter to command: applied=<date>
25+
DB Operation: Execute non query command: insert into [TestSchemaVersions] (ScriptName, Applied) values (@scriptName, @applied)
26+
DB Operation: Dispose command
27+
Info: Upgrade successful
28+
DB Operation: Dispose connection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
DB Operation: Open connection
2+
Info: Beginning database upgrade
3+
Info: Checking whether journal table exists..
4+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions'
5+
DB Operation: Dispose command
6+
Info: Journal table does not exist
7+
Info: Executing Database Server script 'Script0001.sql'
8+
Info: Checking whether journal table exists..
9+
DB Operation: Execute scalar command: SELECT count(name) FROM sqlite_master WHERE type = 'table' AND name = 'SchemaVersions'
10+
DB Operation: Dispose command
11+
Info: Creating the [SchemaVersions] table
12+
DB Operation: Execute non query command: CREATE TABLE [SchemaVersions] (
13+
SchemaVersionID INTEGER CONSTRAINT [PK_SchemaVersions_Id] PRIMARY KEY AUTOINCREMENT NOT NULL,
14+
ScriptName TEXT NOT NULL,
15+
Applied DATETIME NOT NULL
16+
)
17+
DB Operation: Dispose command
18+
Info: The [SchemaVersions] table has been created
19+
DB Operation: Execute non query command: print SubstitutedValue
20+
DB Operation: Dispose command
21+
DB Operation: Create parameter
22+
Info: DB Operation: Add parameter to command: scriptName=Script0001.sql
23+
DB Operation: Create parameter
24+
Info: DB Operation: Add parameter to command: applied=<date>
25+
DB Operation: Execute non query command: insert into [SchemaVersions] (ScriptName, Applied) values (@scriptName, @applied)
26+
DB Operation: Dispose command
27+
Info: Upgrade successful
28+
DB Operation: Dispose connection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[assembly: System.CLSCompliantAttribute(true)]
2+
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
3+
[assembly: System.Runtime.InteropServices.GuidAttribute("9f949414-f078-49bf-b50e-a3859c18fb6e")]
4+
5+
public static class SQLiteExtensions
6+
{
7+
public static DbUp.Builder.UpgradeEngineBuilder JournalToSQLiteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { }
8+
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
9+
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.SQLite.Helpers.SharedConnection sharedConnection) { }
10+
}
11+
namespace DbUp.SQLite
12+
{
13+
public class SQLiteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
14+
{
15+
public SQLiteConnectionManager(string connectionString) { }
16+
public SQLiteConnectionManager(DbUp.SQLite.Helpers.SharedConnection sharedConnection) { }
17+
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
18+
}
19+
public class SQLiteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
20+
{
21+
public SQLiteObjectParser() { }
22+
}
23+
public class SQLitePreprocessor : DbUp.Engine.IScriptPreprocessor
24+
{
25+
public SQLitePreprocessor() { }
26+
public string Process(string contents) { }
27+
}
28+
public class SQLiteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
29+
{
30+
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) { }
31+
protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { }
32+
protected override string GetVerifySchemaSql(string schema) { }
33+
}
34+
public class SQLiteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
35+
{
36+
public SQLiteTableJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string table) { }
37+
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
38+
protected override string DoesTableExistSql() { }
39+
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
40+
protected override string GetJournalEntriesSql() { }
41+
}
42+
}
43+
namespace DbUp.SQLite.Helpers
44+
{
45+
public class InMemorySQLiteDatabase : System.IDisposable
46+
{
47+
public InMemorySQLiteDatabase() { }
48+
public string ConnectionString { get; set; }
49+
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; }
50+
public void Dispose() { }
51+
public DbUp.Engine.Transactions.IConnectionManager GetConnectionManager() { }
52+
}
53+
public class SharedConnection : System.Data.IDbConnection, System.IDisposable
54+
{
55+
public SharedConnection(System.Data.IDbConnection dbConnection) { }
56+
public string ConnectionString { get; set; }
57+
public int ConnectionTimeout { get; }
58+
public string Database { get; }
59+
public System.Data.ConnectionState State { get; }
60+
public System.Data.IDbTransaction BeginTransaction() { }
61+
public System.Data.IDbTransaction BeginTransaction(System.Data.IsolationLevel il) { }
62+
public void ChangeDatabase(string databaseName) { }
63+
public void Close() { }
64+
public System.Data.IDbCommand CreateCommand() { }
65+
public void Dispose() { }
66+
public void DoClose() { }
67+
public void Open() { }
68+
}
69+
public class TemporarySQLiteDatabase : System.IDisposable
70+
{
71+
public TemporarySQLiteDatabase(string name) { }
72+
public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; }
73+
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; }
74+
public void Create() { }
75+
public void Dispose() { }
76+
}
77+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[assembly: System.CLSCompliantAttribute(true)]
2+
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]
3+
[assembly: System.Runtime.InteropServices.GuidAttribute("9f949414-f078-49bf-b50e-a3859c18fb6e")]
4+
5+
public static class SQLiteExtensions
6+
{
7+
public static DbUp.Builder.UpgradeEngineBuilder JournalToSQLiteTable(this DbUp.Builder.UpgradeEngineBuilder builder, string table) { }
8+
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
9+
public static DbUp.Builder.UpgradeEngineBuilder SQLiteDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.SQLite.Helpers.SharedConnection sharedConnection) { }
10+
}
11+
namespace DbUp.SQLite
12+
{
13+
public class SQLiteConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
14+
{
15+
public SQLiteConnectionManager(string connectionString) { }
16+
public SQLiteConnectionManager(DbUp.SQLite.Helpers.SharedConnection sharedConnection) { }
17+
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
18+
}
19+
public class SQLiteObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
20+
{
21+
public SQLiteObjectParser() { }
22+
}
23+
public class SQLitePreprocessor : DbUp.Engine.IScriptPreprocessor
24+
{
25+
public SQLitePreprocessor() { }
26+
public string Process(string contents) { }
27+
}
28+
public class SQLiteScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
29+
{
30+
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) { }
31+
protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { }
32+
protected override string GetVerifySchemaSql(string schema) { }
33+
}
34+
public class SQLiteTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
35+
{
36+
public SQLiteTableJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string table) { }
37+
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
38+
protected override string DoesTableExistSql() { }
39+
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
40+
protected override string GetJournalEntriesSql() { }
41+
}
42+
}
43+
namespace DbUp.SQLite.Helpers
44+
{
45+
public class InMemorySQLiteDatabase : System.IDisposable
46+
{
47+
public InMemorySQLiteDatabase() { }
48+
public string ConnectionString { get; set; }
49+
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; }
50+
public void Dispose() { }
51+
public DbUp.Engine.Transactions.IConnectionManager GetConnectionManager() { }
52+
}
53+
public class SharedConnection : System.Data.IDbConnection, System.IDisposable
54+
{
55+
public SharedConnection(System.Data.IDbConnection dbConnection) { }
56+
public string ConnectionString { get; set; }
57+
public int ConnectionTimeout { get; }
58+
public string Database { get; }
59+
public System.Data.ConnectionState State { get; }
60+
public System.Data.IDbTransaction BeginTransaction() { }
61+
public System.Data.IDbTransaction BeginTransaction(System.Data.IsolationLevel il) { }
62+
public void ChangeDatabase(string databaseName) { }
63+
public void Close() { }
64+
public System.Data.IDbCommand CreateCommand() { }
65+
public void Dispose() { }
66+
public void DoClose() { }
67+
public void Open() { }
68+
}
69+
public class TemporarySQLiteDatabase : System.IDisposable
70+
{
71+
public TemporarySQLiteDatabase(string name) { }
72+
public DbUp.SQLite.Helpers.SharedConnection SharedConnection { get; }
73+
public DbUp.Helpers.AdHocSqlRunner SqlRunner { get; }
74+
public void Create() { }
75+
public void Dispose() { }
76+
}
77+
}

src/Tests/DatabaseSupportTests.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using DbUp.Builder;
2+
using DbUp.SQLite;
3+
using DbUp.Tests.Common;
4+
5+
namespace DbUp.Tests.Providers.SQLite;
6+
7+
public class DatabaseSupportTests : DatabaseSupportTestsBase
8+
{
9+
public DatabaseSupportTests() : base()
10+
{
11+
}
12+
13+
protected override UpgradeEngineBuilder DeployTo(SupportedDatabases to)
14+
=> to.SQLiteDatabase("");
15+
16+
protected override UpgradeEngineBuilder AddCustomNamedJournalToBuilder(UpgradeEngineBuilder builder, string schema, string tableName)
17+
=> builder.JournalTo(
18+
(connectionManagerFactory, logFactory)
19+
=> new SQLiteTableJournal(connectionManagerFactory, logFactory, tableName)
20+
);
21+
}

src/Tests/NoPublicApiChanges.cs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using DbUp.Tests.Common;
2+
3+
namespace DbUp.Tests.Providers.SQLite;
4+
5+
public class NoPublicApiChanges : NoPublicApiChangesBase
6+
{
7+
public NoPublicApiChanges()
8+
: base(typeof(SQLiteExtensions).Assembly)
9+
{
10+
}
11+
}

src/Tests/SQLiteSupportTests.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#if !NETCORE
2+
using System;
3+
using System.Data.SQLite;
4+
using System.IO;
5+
using NUnit.Framework;
6+
using Xunit;
7+
8+
namespace DbUp.Tests.Support.SQLite
9+
{
10+
public class SQLiteSupportTests
11+
{
12+
static readonly string dbFilePath = Path.Combine(Environment.CurrentDirectory, "test.db");
13+
14+
[Fact]
15+
public void CanUseSQLite()
16+
{
17+
var connectionString = string.Format("Data Source={0}; Version=3;", dbFilePath);
18+
19+
if (!File.Exists(dbFilePath))
20+
{
21+
SQLiteConnection.CreateFile(dbFilePath);
22+
}
23+
24+
var upgrader = DeployChanges.To
25+
.SQLiteDatabase(connectionString)
26+
.WithScript("Script0001", "CREATE TABLE IF NOT EXISTS Foo (Id int)")
27+
.Build();
28+
}
29+
}
30+
}
31+
#endif

src/Tests/SQLiteTableJournalTests.cs

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#if !NETCORE
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Data.SQLite;
5+
using DbUp.Engine;
6+
using DbUp.Engine.Output;
7+
using DbUp.Engine.Transactions;
8+
using DbUp.SQLite;
9+
using DbUp.Tests.Common;
10+
using DbUp.Tests.TestInfrastructure;
11+
using NSubstitute;
12+
using Shouldly;
13+
using Xunit;
14+
15+
namespace DbUp.Tests.Support.SQLite
16+
{
17+
public class SQLiteTableJournalTests
18+
{
19+
[Fact]
20+
public void dbversion_is_zero_when_journal_table_not_exist()
21+
{
22+
// Given
23+
var dbConnection = Substitute.For<IDbConnection>();
24+
var command = Substitute.For<IDbCommand>();
25+
dbConnection.CreateCommand().Returns(command);
26+
var connectionManager = Substitute.For<IConnectionManager>();
27+
command.ExecuteScalar().Returns(x => { throw new SQLiteException("table not found"); });
28+
var consoleUpgradeLog = new ConsoleUpgradeLog();
29+
var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions");
30+
31+
// When
32+
var scripts = journal.GetExecutedScripts();
33+
34+
// Expect
35+
command.DidNotReceive().ExecuteReader();
36+
scripts.ShouldBeEmpty();
37+
}
38+
39+
[Fact]
40+
public void creates_a_new_journal_table_when_not_exist()
41+
{
42+
// Given
43+
var dbConnection = Substitute.For<IDbConnection>();
44+
var connectionManager = new TestConnectionManager(dbConnection);
45+
connectionManager.OperationStarting(new ConsoleUpgradeLog(), new List<SqlScript>());
46+
47+
var command = Substitute.For<IDbCommand>();
48+
var param1 = Substitute.For<IDbDataParameter>();
49+
var param2 = Substitute.For<IDbDataParameter>();
50+
dbConnection.CreateCommand().Returns(command);
51+
command.CreateParameter().Returns(param1, param2);
52+
command.ExecuteScalar().Returns(x => 0);
53+
var consoleUpgradeLog = new ConsoleUpgradeLog();
54+
var journal = new SQLiteTableJournal(() => connectionManager, () => consoleUpgradeLog, "SchemaVersions");
55+
56+
// When
57+
journal.StoreExecutedScript(new SqlScript("test", "select 1"), () => command);
58+
59+
// Expect
60+
command.Received(2).CreateParameter();
61+
param1.ParameterName.ShouldBe("scriptName");
62+
param2.ParameterName.ShouldBe("applied");
63+
command.Received().ExecuteNonQuery();
64+
}
65+
}
66+
}
67+
#endif

0 commit comments

Comments
 (0)