Skip to content

Commit c78397f

Browse files
jez9999droyad
authored andcommitted
Use factory to generate DB creation script instead.
# Conflicts: # src/dbup-tests/Support/SqlServer/ApprovalFiles/dbup-sqlserver.netfx.approved.cs
1 parent 1363fa3 commit c78397f

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Tests/ApprovalFiles/NoPublicApiChanges.Run.approved.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase sup
1717
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, string collation) { }
1818
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
1919
public static bool SqlDatabase(this DbUp.SupportedDatabasesForEnsureDatabase supported, string connectionString, int commandTimeout, DbUp.SqlServer.AzureDatabaseEdition azureDatabaseEdition, string collation) { }
20-
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) { }
21-
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) { }
20+
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) { }
21+
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) { }
2222
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString) { }
2323
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, string connectionString, string schema) { }
2424
public static DbUp.Builder.UpgradeEngineBuilder SqlDatabase(this DbUp.Builder.SupportedDatabases supported, DbUp.Engine.Transactions.IConnectionManager connectionManager, string schema = null) { }

src/dbup-sqlserver/SqlServerExtensions.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supporte
214214
/// <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>
215215
/// <param name="azureDatabaseEdition">Azure edition to Create</param>
216216
/// <param name="collation">The collation name to set during database creation</param>
217-
/// <param name="createDbSqlCommands">A list of custom SQL commands that will be used to create the database.</param>
217+
/// <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>
218218
/// <param name="checkOnly">If true, only checks whether the database would've been created but does not perform the creation.</param>
219219
/// <returns>True if the database was (or would've been) created; otherwise false.</returns>
220-
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)
220+
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)
221221
{
222-
return SqlDatabase(supported, connectionString, new ConsoleUpgradeLog(), commandTimeout, azureDatabaseEdition, collation, createDbSqlCommands, checkOnly);
222+
return SqlDatabase(supported, connectionString, new ConsoleUpgradeLog(), commandTimeout, azureDatabaseEdition, collation, createDbSqlCommandsFactory, checkOnly);
223223
}
224224

225225
/// <summary>
@@ -231,7 +231,7 @@ public static bool SqlDatabase(this SupportedDatabasesForEnsureDatabase supporte
231231
/// <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>
232232
/// <param name="azureDatabaseEdition">Use to indicate that the SQL server database is in Azure</param>
233233
/// <param name="collation">The collation name to set during database creation</param>
234-
/// <param name="createDbSqlCommands">A list of custom SQL commands that will be used to create the database.</param>
234+
/// <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>
235235
/// <param name="checkOnly">If true, only checks whether the database would've been created but does not perform the creation.</param>
236236
/// <returns>True if the database was (or would've been) created; otherwise false.</returns>
237237
public static bool SqlDatabase(
@@ -241,7 +241,7 @@ public static bool SqlDatabase(
241241
int timeout = -1,
242242
AzureDatabaseEdition azureDatabaseEdition = AzureDatabaseEdition.None,
243243
string collation = null,
244-
IList<string> createDbSqlCommands = null,
244+
Func<string, IList<string>> createDbSqlCommandsFactory = null,
245245
bool checkOnly = false)
246246
{
247247
GetMasterConnectionStringBuilder(connectionString, logger, out var masterConnectionString, out var databaseName);
@@ -267,7 +267,8 @@ public static bool SqlDatabase(
267267
if (checkOnly)
268268
return true;
269269

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

292293
createDbSqlCommands.Add(sqlCommandText);
293294
}
295+
else
296+
{
297+
createDbSqlCommands = createDbSqlCommandsFactory(databaseName);
298+
}
294299

295300
// Create the database...
296301
foreach (var sqlCommandText in createDbSqlCommands)

0 commit comments

Comments
 (0)