DepartmentProject/DepartmentPortal/Common/DatabaseCore/Scripts/SecureMigrationScript.cs

57 lines
2.6 KiB
C#

using Microsoft.EntityFrameworkCore;
namespace DatabaseCore.Scripts
{
/// <summary>
/// Скрипты для миграции данных по безопасности
/// </summary>
public static class SecureMigrationScript
{
private static readonly string clearMigration =
@"DELETE FROM DepartmentDatabasePortal.dbo.EnviromentSettings
GO
DELETE FROM DepartmentDatabasePortal.dbo.Accesses;
GO
DELETE FROM DepartmentDatabasePortal.dbo.UserRoles;
GO
DELETE FROM DepartmentDatabasePortal.dbo.Users;
GO
DELETE FROM DepartmentDatabasePortal.dbo.Roles;
GO";
private static readonly string roleMigration =
@"INSERT INTO DepartmentDatabasePortal.dbo.Roles(Id, RoleName, RolePriority, DateCreate, DateDelete, IsDeleted)
SELECT Id, RoleName, RolePriority, DateCreate, DateDelete, IsDeleted FROM DepartmentDatabaseContext.dbo.DepartmentRoles";
private static readonly string userMigration =
@"INSERT INTO DepartmentDatabasePortal.dbo.Users(Id, UserName, PasswordHash, StudentId, LecturerId, Avatar, DateLastVisit, IsBanned, DateBanned, CountAttempt, DateCreate, DateDelete, IsDeleted)
SELECT Id, UserName, PasswordHash, StudentId, LecturerId, Avatar, DateLastVisit, IsLocked, DateBanned, CountAttempt, DateCreate, DateDelete, IsDeleted FROM DepartmentDatabaseContext.dbo.DepartmentUsers";
private static readonly string userroleMigration =
@"INSERT INTO DepartmentDatabasePortal.dbo.UserRoles(Id, UserId, RoleId, DateCreate, DateDelete, IsDeleted)
SELECT Id, UserId, RoleId, DateCreate, DateDelete, IsDeleted FROM DepartmentDatabaseContext.dbo.DepartmentUserRoles";
private static readonly string accessMigration =
@"INSERT INTO DepartmentDatabasePortal.dbo.Accesses(Id, Operation, AccessType, RoleId, DateCreate, DateDelete, IsDeleted)
SELECT Id, Operation, AccessType, RoleId, DateCreate, DateDelete, IsDeleted FROM DepartmentDatabaseContext.dbo.DepartmentAccesses";
private static readonly string enviromentsettingMigration =
@"INSERT INTO DepartmentDatabasePortal.dbo.EnviromentSettings(Id, [Key], [Value])
SELECT NEWID(), [Key], [Value] FROM DepartmentDatabaseContext.dbo.CurrentSettings";
/// <summary>
/// Перенос данных по безопасности
/// </summary>
/// <param name="context"></param>
public static void RunScript(DbContext context)
{
context.Database.ExecuteSqlRaw(clearMigration, null);
context.Database.ExecuteSqlRaw(roleMigration, null);
context.Database.ExecuteSqlRaw(userMigration, null);
context.Database.ExecuteSqlRaw(userroleMigration, null);
context.Database.ExecuteSqlRaw(accessMigration, null);
context.Database.ExecuteSqlRaw(enviromentsettingMigration, null);
}
}
}