|
|
|
@ -40,18 +40,14 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
|
|
|
|
public async Task MigrateAsync() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (DbMigrationsProjectExists() && !MigrationsFolderExists()) |
|
|
|
{ |
|
|
|
AddInitialMigration(); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
//<TEMPLATE-REMOVE IF-NOT='EFCORE'>
|
|
|
|
var initialMigrationAdded = AddInitialMigrationIfNotExist(); |
|
|
|
|
|
|
|
if (initialMigrationAdded) |
|
|
|
{ |
|
|
|
Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message); |
|
|
|
return; |
|
|
|
} |
|
|
|
//</TEMPLATE-REMOVE>
|
|
|
|
|
|
|
|
Logger.LogInformation("Started database migrations..."); |
|
|
|
|
|
|
|
@ -112,6 +108,40 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
//<TEMPLATE-REMOVE IF-NOT='EFCORE'>
|
|
|
|
private bool AddInitialMigrationIfNotExist() |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
if (!DbMigrationsProjectExists()) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
if (!MigrationsFolderExists()) |
|
|
|
{ |
|
|
|
AddInitialMigration(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception e) |
|
|
|
{ |
|
|
|
Logger.LogWarning("Couldn't determinate if any migrations exist : " + e.Message); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private bool DbMigrationsProjectExists() |
|
|
|
{ |
|
|
|
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath(); |
|
|
|
@ -123,7 +153,7 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
{ |
|
|
|
var dbMigrationsProjectFolder = GetDbMigrationsProjectFolderPath(); |
|
|
|
|
|
|
|
return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "migrations")); |
|
|
|
return Directory.Exists(Path.Combine(dbMigrationsProjectFolder, "Migrations")); |
|
|
|
} |
|
|
|
|
|
|
|
private void AddInitialMigration() |
|
|
|
@ -144,7 +174,7 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
fileName = "cmd.exe"; |
|
|
|
} |
|
|
|
|
|
|
|
var procStartInfo = new ProcessStartInfo( fileName, |
|
|
|
var procStartInfo = new ProcessStartInfo(fileName, |
|
|
|
$"{argumentPrefix} \"abp create-migration-and-run-migrator \"{GetDbMigrationsProjectFolderPath()}\"\"" |
|
|
|
); |
|
|
|
|
|
|
|
@ -189,5 +219,6 @@ namespace MyCompanyName.MyProjectName.Data |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
//</TEMPLATE-REMOVE>
|
|
|
|
} |
|
|
|
} |
|
|
|
|