Skip to content

Commit

Permalink
Use factory to generate DB creation script instead.
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/dbup-tests/Support/SqlServer/ApprovalFiles/dbup-sqlserver.netfx.approved.cs
  • Loading branch information
jez9999 authored and droyad committed Oct 22, 2024
1 parent 1363fa3 commit c78397f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase sup
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Collections.Generic.IList<string> createDbSqlCommands = null, bool checkOnly = false) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Collections.Generic.IList<string> createDbSqlCommands = null, bool checkOnly = false) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Func<string, System.Collections.Generic.IList<string>> createDbSqlCommandsFactory = null, bool checkOnly = false) { }
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.Engine.Output.IUpgradeLog logger, int timeout = -1, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition = 0, string collation = null, System.Func<string, System.Collections.Generic.IList<string>> createDbSqlCommandsFactory = null, bool checkOnly = false) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema = null) { }
Expand Down
17 changes: 11 additions & 6 deletions src/dbup-sqlserver/SqlServerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supporte
/// <param name="commandTimeout">Use this to set the command time out for creating a database in case you're encountering a time out in this operation.</param>
/// <param name="azureDatabaseEdition">Azure edition to Create</param>
/// <param name="collation">The collation name to set during database creation</param>
/// <param name="createDbSqlCommands">A list of custom SQL commands that will be used to create the database.</param>
/// <param name="createDbSqlCommandsFactory">A factory receiving the DB name, and returning a list of custom SQL commands that will be used to create the database.</param>
/// <param name="checkOnly">If true, only checks whether the database would've been created but does not perform the creation.</param>
/// <returns>True if the database was (or would've been) created; otherwise false.</returns>
public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout = -1, AzureDatabaseEdition azureDatabaseEdition = AzureDatabaseEdition.None, string collation = null, IList<string> createDbSqlCommands = null, bool checkOnly = false)
public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout = -1, AzureDatabaseEdition azureDatabaseEdition = AzureDatabaseEdition.None, string collation = null, Func<string, IList<string>> createDbSqlCommandsFactory = null, bool checkOnly = false)
{
return SqlDatabase(supported, connectionString, new ConsoleUpgradeLog(), commandTimeout, azureDatabaseEdition, collation, createDbSqlCommands, checkOnly);
return SqlDatabase(supported, connectionString, new ConsoleUpgradeLog(), commandTimeout, azureDatabaseEdition, collation, createDbSqlCommandsFactory, checkOnly);
}

/// <summary>
Expand All @@ -231,7 +231,7 @@ public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supporte
/// <param name="timeout">Use this to set the command time out for creating a database in case you're encountering a time out in this operation.</param>
/// <param name="azureDatabaseEdition">Use to indicate that the SQL server database is in Azure</param>
/// <param name="collation">The collation name to set during database creation</param>
/// <param name="createDbSqlCommands">A list of custom SQL commands that will be used to create the database.</param>
/// <param name="createDbSqlCommandsFactory">A factory receiving the DB name, and returning a list of custom SQL commands that will be used to create the database.</param>
/// <param name="checkOnly">If true, only checks whether the database would've been created but does not perform the creation.</param>
/// <returns>True if the database was (or would've been) created; otherwise false.</returns>
public static bool SqlDatabase(
Expand All @@ -241,7 +241,7 @@ public static bool SqlDatabase(
int timeout = -1,
AzureDatabaseEdition azureDatabaseEdition = AzureDatabaseEdition.None,
string collation = null,
IList<string> createDbSqlCommands = null,
Func<string, IList<string>> createDbSqlCommandsFactory = null,
bool checkOnly = false)
{
GetMasterConnectionStringBuilder(connectionString, logger, out var masterConnectionString, out var databaseName);
Expand All @@ -267,7 +267,8 @@ public static bool SqlDatabase(
if (checkOnly)
return true;

if (createDbSqlCommands == null)
IList<string> createDbSqlCommands;
if (createDbSqlCommandsFactory == null)
{
createDbSqlCommands = new List<string>();
var collationString = string.IsNullOrEmpty(collation) ? "" : $@" COLLATE {collation}";
Expand All @@ -291,6 +292,10 @@ public static bool SqlDatabase(

createDbSqlCommands.Add(sqlCommandText);
}
else
{
createDbSqlCommands = createDbSqlCommandsFactory(databaseName);
}

// Create the database...
foreach (var sqlCommandText in createDbSqlCommands)
Expand Down

0 comments on commit c78397f

Please sign in to comment.