Skip to content

Commit

Permalink
Copied over from main project
Browse files Browse the repository at this point in the history
  • Loading branch information
droyad committed Jan 24, 2024
1 parent b3866bf commit 6291130
Show file tree
Hide file tree
Showing 25 changed files with 652 additions and 43 deletions.
8 changes: 8 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,11 @@ csharp_preserve_single_line_blocks = true
[*.vb]
# Modifier preferences
visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public,Friend,NotOverridable,Overridable,MustOverride,Overloads,Overrides,MustInherit,NotInheritable,Static,Shared,Shadows,ReadOnly,WriteOnly,Dim,Const,WithEvents,Widening,Narrowing,Custom,Async:suggestion
###############################
# XML and csproj #
###############################
[*.{xml,csproj}]
max_line_length = off
trim_trailing_whitespace = true
insert_final_newline = true
indent_size = 2
57 changes: 57 additions & 0 deletions src/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Diagnostics;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using DbUp;

namespace FirebirdSampleApplication
{
class Program
{
static int Main()
{
var config = GetConfig();
string connectionString = config.GetConnectionString("SampleFirebird");

var upgrader =
DeployChanges.To
.FirebirdDatabase(connectionString)
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.WithTransactionPerScript()
.LogToConsole()
.Build();

var result = upgrader.PerformUpgrade();

if (!result.Successful)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(result.Error);
Console.ResetColor();

WaitIfDebug();
return -1;
}

Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Success!");
Console.ResetColor();
WaitIfDebug();
return 0;
}

private static IConfiguration GetConfig()
{
IConfiguration config = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();
return config;
}

[Conditional("DEBUG")]
public static void WaitIfDebug()
{
Console.ReadLine();
}
}
}
22 changes: 22 additions & 0 deletions src/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\dbup-firebird\dbup-firebird.csproj"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0"/>
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Scripts\*.sql"/>
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Sample/Scripts/Script0001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE Testing1 (ID integer NOT NULL)
4 changes: 4 additions & 0 deletions src/Sample/Scripts/Script0002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE Testing2 (ID integer NOT NULL)
;
CREATE TABLE Testing3 (ID integer NOT NULL)
;
4 changes: 4 additions & 0 deletions src/Sample/Scripts/Script0003.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE Testing4 (ID integer NOT NULL)
;
CREATE TABLE Testing5 (ID integer NOT NULL)
;
4 changes: 4 additions & 0 deletions src/Sample/Scripts/Script0004.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE Testing6 (ID integer NOT NULL)
;
CREATE TABLE Testing7 (ID integer NOT NULL)
;
5 changes: 5 additions & 0 deletions src/Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ConnectionStrings": {
"SampleFirebird": "User=SOMEUSER;Password=SOMEPWD;Database=c:\\somedb.fdb;DataSource=SOMESERVERNAME;Port=SOMEPORT;Dialect=3;Charset=ISO8859_1;ServerType=0;Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=50;"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists..
DB Operation: Execute scalar command: select 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_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 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_NAME = 'schemaversions'
DB Operation: Dispose command
Info: Creating the "schemaversions" table
DB Operation: Execute non query command: CREATE TABLE "schemaversions"
(
schemaversionsid INTEGER NOT NULL,
scriptname VARCHAR(255) NOT NULL,
applied TIMESTAMP NOT NULL,
CONSTRAINT pk_schemaversions_id PRIMARY KEY (schemaversionsid)
)
DB Operation: Dispose command
Info: The "schemaversions" table has been created
DB Operation: Execute non query command: CREATE SEQUENCE GEN_schemaversionsID
DB Operation: Dispose command
Info: The GEN_schemaversionsID generator has been created
DB Operation: Execute non query command: CREATE TRIGGER BI_schemaversionsID FOR "schemaversions" ACTIVE BEFORE INSERT POSITION 0 AS BEGIN
if (new.schemaversionsid is null or (new.schemaversionsid = 0)) then new.schemaversionsid = gen_id(GEN_schemaversionsID,1);
END;
DB Operation: Dispose command
Info: The BI_schemaversionsID trigger 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists..
DB Operation: Execute scalar command: select 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_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 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_NAME = 'TestSchemaVersions'
DB Operation: Dispose command
Info: Creating the "TestSchemaVersions" table
DB Operation: Execute non query command: CREATE TABLE "TestSchemaVersions"
(
schemaversionsid INTEGER NOT NULL,
scriptname VARCHAR(255) NOT NULL,
applied TIMESTAMP NOT NULL,
CONSTRAINT pk_TestSchemaVersions_id PRIMARY KEY (schemaversionsid)
)
DB Operation: Dispose command
Info: The "TestSchemaVersions" table has been created
DB Operation: Execute non query command: CREATE SEQUENCE GEN_TestSchemaVersionsID
DB Operation: Dispose command
Info: The GEN_TestSchemaVersionsID generator has been created
DB Operation: Execute non query command: CREATE TRIGGER BI_TestSchemaVersionsID FOR "TestSchemaVersions" ACTIVE BEFORE INSERT POSITION 0 AS BEGIN
if (new.schemaversionsid is null or (new.schemaversionsid = 0)) then new.schemaversionsid = gen_id(GEN_TestSchemaVersionsID,1);
END;
DB Operation: Dispose command
Info: The BI_TestSchemaVersionsID trigger 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists..
DB Operation: Execute scalar command: select 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_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 1 from RDB$RELATIONS where RDB$SYSTEM_FLAG = 0 and RDB$RELATION_NAME = 'schemaversions'
DB Operation: Dispose command
Info: Creating the "schemaversions" table
DB Operation: Execute non query command: CREATE TABLE "schemaversions"
(
schemaversionsid INTEGER NOT NULL,
scriptname VARCHAR(255) NOT NULL,
applied TIMESTAMP NOT NULL,
CONSTRAINT pk_schemaversions_id PRIMARY KEY (schemaversionsid)
)
DB Operation: Dispose command
Info: The "schemaversions" table has been created
DB Operation: Execute non query command: CREATE SEQUENCE GEN_schemaversionsID
DB Operation: Dispose command
Info: The GEN_schemaversionsID generator has been created
DB Operation: Execute non query command: CREATE TRIGGER BI_schemaversionsID FOR "schemaversions" ACTIVE BEFORE INSERT POSITION 0 AS BEGIN
if (new.schemaversionsid is null or (new.schemaversionsid = 0)) then new.schemaversionsid = gen_id(GEN_schemaversionsID,1);
END;
DB Operation: Dispose command
Info: The BI_schemaversionsID trigger 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
43 changes: 43 additions & 0 deletions src/Tests/ApprovalFiles/NoPublicApiChanges.Run.DotNet.verified.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[assembly: System.CLSCompliantAttribute(true)]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]

public static class FirebirdExtensions
{
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
}
namespace DbUp.Firebird
{
public class FirebirdConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
{
public FirebirdConnectionManager(string connectionString) { }
protected override DbUp.Engine.Transactions.AllowedTransactionMode AllowedTransactionModes { get; }
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
}
public class FirebirdObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
{
public FirebirdObjectParser() { }
}
public class FirebirdPreprocessor : DbUp.Engine.IScriptPreprocessor
{
public FirebirdPreprocessor() { }
public string Process(string contents) { }
}
public class FirebirdScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
{
public FirebirdScriptExecutor(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> journal) { }
protected override bool UseTheSameTransactionForJournalTableAndScripts { get; }
protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { }
protected override string GetVerifySchemaSql(string schema) { }
}
public class FirebirdTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
{
public FirebirdTableJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string tableName) { }
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
protected override string DoesTableExistSql() { }
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
protected override string GetJournalEntriesSql() { }
protected override void OnTableCreated(System.Func<System.Data.IDbCommand> dbCommandFactory) { }
}
}
43 changes: 43 additions & 0 deletions src/Tests/ApprovalFiles/NoPublicApiChanges.Run.Net.verified.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[assembly: System.CLSCompliantAttribute(true)]
[assembly: System.Runtime.InteropServices.ComVisibleAttribute(false)]

public static class FirebirdExtensions
{
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder FirebirdDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
}
namespace DbUp.Firebird
{
public class FirebirdConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
{
public FirebirdConnectionManager(string connectionString) { }
protected override DbUp.Engine.Transactions.AllowedTransactionMode AllowedTransactionModes { get; }
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
}
public class FirebirdObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
{
public FirebirdObjectParser() { }
}
public class FirebirdPreprocessor : DbUp.Engine.IScriptPreprocessor
{
public FirebirdPreprocessor() { }
public string Process(string contents) { }
}
public class FirebirdScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
{
public FirebirdScriptExecutor(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> journal) { }
protected override bool UseTheSameTransactionForJournalTableAndScripts { get; }
protected override void ExecuteCommandsWithinExceptionHandler(int index, DbUp.Engine.SqlScript script, System.Action executeCommand) { }
protected override string GetVerifySchemaSql(string schema) { }
}
public class FirebirdTableJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
{
public FirebirdTableJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string tableName) { }
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
protected override string DoesTableExistSql() { }
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
protected override string GetJournalEntriesSql() { }
protected override void OnTableCreated(System.Func<System.Data.IDbCommand> dbCommandFactory) { }
}
}
23 changes: 23 additions & 0 deletions src/Tests/DatabaseSupportTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#if !NETCORE
using DbUp.Builder;
using DbUp.Firebird;
using DbUp.Tests.Common;

namespace DbUp.Tests.Providers.Firebird;

public class DatabaseSupportTests : DatabaseSupportTestsBase
{
public DatabaseSupportTests() : base()
{
}

protected override UpgradeEngineBuilder DeployTo(SupportedDatabases to)
=> to.FirebirdDatabase("");

protected override UpgradeEngineBuilder AddCustomNamedJournalToBuilder(UpgradeEngineBuilder builder, string schema, string tableName)
=> builder.JournalTo(
(connectionManagerFactory, logFactory)
=> new FirebirdTableJournal(connectionManagerFactory, logFactory, tableName)
);
}
#endif
13 changes: 13 additions & 0 deletions src/Tests/NoPublicApiChanges.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#if !NETCORE
using DbUp.Tests.Common;

namespace DbUp.Tests.Providers.Firebird;

public class NoPublicApiChanges : NoPublicApiChangesBase
{
public NoPublicApiChanges()
: base(typeof(FirebirdExtensions).Assembly)
{
}
}
#endif
Loading

0 comments on commit 6291130

Please sign in to comment.