Skip to content
Open
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
84 changes: 84 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
variables:
# Opt out of telemetry (turbo and others), see https://consoledonottrack.com/
DO_NOT_TRACK: 1
# Enable debug services
CI_DEBUG_SERVICES: "true"
# Enable service network
FF_NETWORK_PER_BUILD: "true"
# Nupkg folder
NUPKG_FOLDER: ".packages"
NUGET_SOURCE: https://nuget.rapidsoft.ru/nuget/Rapidsoft-Nuget/v3/index.json
NUGETORG_SOURCE: https://nuget.rapidsoft.ru/nuget/RapidSoft-NuGetORG/v3/index.json
GITHUB_SOURCE: https://nuget.pkg.github.com/DbUp/index.json
# All console output of dotnet should be in English
LANG: C
LCID: 1033
# Disable dotnet first time experience
DOTNET_NOLOGO: true
# Disable Husky in dotnet tools restore
HUSKY: 0

stages:
- build
- test
- publish
- release

workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "push" && $CI_COMMIT_TAG'
when: never
- if: $CI_COMMIT_BRANCH
when: always

include:
- component: $CI_SERVER_FQDN/open-source/ci-components/[email protected]

build:
image: mcr.microsoft.com/dotnet/sdk:9.0
stage: build
variables:
PACKAGE_VERSION: ${GitVersion_LegacySemVer}
script:
- |
echo "Building version ${PACKAGE_VERSION}"
if [[ "${CI_SCRIPT_TRACE}" == "true" ]] || [[ -n "${CI_DEBUG_TRACE}" ]]; then
echo "Debugging enabled"
set -xv
fi
dotnet nuget update source nuget.org -s "$NUGETORG_SOURCE"
dotnet nuget add source "$NUGET_SOURCE" --name nuget.rapidsoft.ru
dotnet nuget add source "$GITHUB_SOURCE" --name github --username shokurov --password $GITHUB_REPO_KEY --store-password-in-clear-text

dotnet restore --packages .nuget/packages/ ./src/dbup-clickhouse.sln
dotnet build --no-restore --packages .nuget/packages/ -c Release -p:Version=$PACKAGE_VERSION ./src/dbup-clickhouse.sln
dotnet pack --no-build --no-restore -c Release -p:Version=$PACKAGE_VERSION -o $NUPKG_FOLDER --include-symbols --include-source ./src/dbup-clickhouse.sln
artifacts:
expire_in: 1 week # to save gitlab server space, we copy the files we need to deploy folder later on
paths:
- "$NUPKG_FOLDER/"

publish:internal:
image: mcr.microsoft.com/dotnet/sdk:9.0
stage: publish
variables:
PACKAGE_VERSION: ${GitVersion_LegacySemVer}
script:
- echo "Publishing version $PACKAGE_VERSION internally to $NUGET_SOURCE"
- dotnet nuget push "$NUPKG_FOLDER/*.nupkg" --source $NUGET_SOURCE --api-key $NUGET_API_KEY
needs:
- build
when: manual

# Please see [Release CI/CD examples](https://docs.gitlab.com/ee/user/project/releases/release_cicd_examples.html) for many rich examples for triggering a release only on specific conditions.
release_job:
stage: release
when: manual
image: registry.gitlab.com/gitlab-org/cli:latest
variables:
PACKAGE_VERSION: ${GitVersion_LegacySemVer}
script:
- echo "running release_job"
release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
tag_name: '$PACKAGE_VERSION'
description: '$PACKAGE_VERSION'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Prerelease](https://img.shields.io/nuget/vpre/dbup-clickhouse?color=orange&label=prerelease)](https://www.nuget.org/packages/dbup-clickhouse)

# DbUp ClickHouse support
DbUp is a .NET library that helps you to deploy changes to SQL Server databases. It tracks which SQL scripts have been run already, and runs the change scripts that are needed to get your database up to date.
DbUp is a .NET library that helps you to deploy changes to databases. It tracks which SQL scripts have been run already and runs the change scripts that are needed to get your database up to date. This package adds ClickHouse support.

## Getting Help
To learn more about DbUp check out the [documentation](https://dbup.readthedocs.io/en/latest/)
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackageReleaseNotes>https://github.com/DbUp/dbup-clickhouse/releases</PackageReleaseNotes>
<PackageProjectUrl>https://dbup.github.io</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/dbup-clickhouse/dbup-clickhouse.git</RepositoryUrl>
<RepositoryUrl>https://github.com/DbUp/dbup-clickhouse.git</RepositoryUrl>
<LangVersion>latest</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists
DB Operation: Execute scalar command: EXISTS TABLE 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: EXISTS TABLE schemaversions
DB Operation: Dispose command
Info: Creating the `schemaversions` table
DB Operation: Execute non query command: CREATE TABLE `schemaversions`
(
ScriptName String,
Applied DateTime
)
ENGINE = MergeTree()
ORDER BY (ScriptName)
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists
DB Operation: Execute scalar command: EXISTS TABLE `test`.`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: EXISTS TABLE `test`.`TestSchemaVersions`
DB Operation: Dispose command
Info: Creating the `test`.`TestSchemaVersions` table
DB Operation: Execute non query command: CREATE TABLE `test`.`TestSchemaVersions`
(
ScriptName String,
Applied DateTime
)
ENGINE = MergeTree()
ORDER BY (ScriptName)
DB Operation: Dispose command
Info: The `test`.`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 `test`.`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,30 @@
DB Operation: Open connection
Info: Beginning database upgrade
Info: Checking whether journal table exists
DB Operation: Execute scalar command: EXISTS TABLE 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: EXISTS TABLE schemaversions
DB Operation: Dispose command
Info: Creating the `schemaversions` table
DB Operation: Execute non query command: CREATE TABLE `schemaversions`
(
ScriptName String,
Applied DateTime
)
ENGINE = MergeTree()
ORDER BY (ScriptName)
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
38 changes: 32 additions & 6 deletions src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@

namespace DbUp.ClickHouse
{
public class ClickHouseConnectionManager : DbUp.Engine.Transactions.DatabaseConnectionManager, DbUp.Engine.Transactions.IConnectionManager
{
public ClickHouseConnectionManager(string connectionString) { }
public override System.Collections.Generic.IEnumerable<string> SplitScriptIntoCommands(string scriptContents) { }
}
public static class ClickHouseExtensions
{
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(this DbUp.Builder.SupportedDatabases supportedDatabases, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager) { }
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema) { }
public static DbUp.Builder.UpgradeEngineBuilder ClickHouseDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string database) { }
public static DbUp.Builder.UpgradeEngineBuilder JournalToClickHouseTable(this DbUp.Builder.UpgradeEngineBuilder builder, string schema, string table) { }
}
public class ClickHouseJournal : DbUp.Support.TableJournal, DbUp.Engine.IJournal
{
public ClickHouseJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManager, System.Func<DbUp.Engine.Output.IUpgradeLog> logger, string schema, string tableName) { }
protected override string CreateSchemaTableSql(string quotedPrimaryKeyName) { }
protected override string DoesTableExistSql() { }
protected override string GetInsertJournalEntrySql(string scriptName, string applied) { }
protected override string GetJournalEntriesSql() { }
}
public class ClickHouseObjectParser : DbUp.Support.SqlObjectParser, DbUp.Engine.ISqlObjectParser
{
public ClickHouseObjectParser() { }
}
public class ClickHousePreprocessor : DbUp.Engine.IScriptPreprocessor
{
public ClickHousePreprocessor() { }
public string Process(string contents) { }
}
public class ClickHouseJournal : DbUp.Engine.IJournal
public class ClickHouseScriptExecutor : DbUp.Support.ScriptExecutor, DbUp.Engine.IScriptExecutor
{
public ClickHouseJournal(System.Func<DbUp.Engine.Transactions.IConnectionManager> connectionManagerFactory, System.Func<DbUp.Engine.Output.IUpgradeLog> logFactory, string tableName) { }
public void EnsureTableExistsAndIsLatestVersion(System.Func<System.Data.IDbCommand> dbCommandFactory) { }
public string[] GetExecutedScripts() { }
public void StoreExecutedScript(DbUp.Engine.SqlScript script, System.Func<System.Data.IDbCommand> dbCommandFactory) { }
public ClickHouseScriptExecutor(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) { }
}
}
34 changes: 34 additions & 0 deletions src/Tests/ClickHouseContainerFixture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Testcontainers.ClickHouse;
using Xunit;

namespace DbUp.ClickHouse.Tests;

/// <summary>
/// Class fixture for a ClickHouse container that is shared across all tests in a test class.
/// This ensures the container is created once per test class rather than once per test.
/// </summary>
public class ClickHouseContainerFixture : IAsyncLifetime
{
private ClickHouseContainer? clickhouseContainer;
public string ConnectionString { get; private set; } = string.Empty;

public async Task InitializeAsync()
{
// Create and start a ClickHouse container
var container = new ClickHouseBuilder().WithDatabase("testdb")
.Build();

await container.StartAsync();

ConnectionString = container.GetConnectionString();
clickhouseContainer = container;
}

public async Task DisposeAsync()
{
if (clickhouseContainer != null)
{
await clickhouseContainer.DisposeAsync();
}
}
}
Loading