Added support for migrating existing Oqtane installations from DbUp to Migrations. Also added a Migration for version 2.0.2, and set current version to 2.1.0
This commit is contained in:
@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Oqtane.Interfaces;
|
||||
using Oqtane.Migrations.EntityBuilders;
|
||||
using Oqtane.Repository;
|
||||
|
||||
namespace Oqtane.Migrations
|
||||
{
|
||||
[DbContext(typeof(TenantDBContext))]
|
||||
[Migration("Tenant.02.01.00.00")]
|
||||
|
||||
public class AddAppVersionsTable : MultiDatabaseMigration
|
||||
{
|
||||
public AddAppVersionsTable(IEnumerable<IOqtaneDatabase> databases) : base(databases)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
//Create AppVersions table
|
||||
var appVersionsEntityBuilder = new AppVersionsEntityBuilder(migrationBuilder, ActiveDatabase);
|
||||
appVersionsEntityBuilder.Create();
|
||||
|
||||
//Finish SqlServer Migration from DbUp
|
||||
if (ActiveDatabase.Name == "SqlServer" || ActiveDatabase.Name == "LocalDB")
|
||||
{
|
||||
//Version 1.0.0
|
||||
InsertVersion(migrationBuilder, "01.00.00", "Oqtane.Scripts.Master.00.09.00.00.sql");
|
||||
|
||||
//Version 1.0.1
|
||||
InsertVersion(migrationBuilder, "01.00.01", "Oqtane.Scripts.Master.01.00.01.00.sql");
|
||||
|
||||
//Version 1.0.2
|
||||
InsertVersion(migrationBuilder, "01.00.02", "Oqtane.Scripts.Tenant.01.00.02.01.sql");
|
||||
|
||||
//Version 2.0.0
|
||||
InsertVersion(migrationBuilder, "02.00.00", "Oqtane.Scripts.Tenant.02.00.00.01.sql");
|
||||
|
||||
//Version 2.0.1
|
||||
InsertVersion(migrationBuilder, "02.00.01", "Oqtane.Scripts.Tenant.02.00.01.03.sql");
|
||||
|
||||
//Version 2.0.2
|
||||
InsertVersion(migrationBuilder, "02.00.02", "Oqtane.Scripts.Tenant.02.00.02.01.sql");
|
||||
|
||||
//Drop SchemaVersions
|
||||
migrationBuilder.Sql(@"
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersions') AND OBJECTPROPERTY(id, N'IsTable') = 1)
|
||||
BEGIN
|
||||
DROP TABLE SchemaVersions
|
||||
END");
|
||||
}
|
||||
|
||||
//Version 2.1.0
|
||||
migrationBuilder.Sql($@"
|
||||
INSERT INTO AppVersions(Version, AppliedDate)
|
||||
VALUES('02.01.00', '{DateTime.UtcNow:u}')
|
||||
");
|
||||
}
|
||||
|
||||
private void InsertVersion(MigrationBuilder migrationBuilder, string version, string scriptName)
|
||||
{
|
||||
migrationBuilder.Sql($@"
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'dbo.SchemaVersions') AND OBJECTPROPERTY(id, N'IsTable') = 1)
|
||||
BEGIN
|
||||
INSERT INTO AppVersions(Version, AppliedDate)
|
||||
SELECT Version = '{version}', Applied As AppliedDate
|
||||
FROM SchemaVersions
|
||||
WHERE ScriptName = '{scriptName}'
|
||||
END
|
||||
");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user