2021-03-26 20:09:52 +04:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace DatabaseCore.Scripts
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Скрипты для миграции данных по безопасности
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static class SecureMigrationScript
|
|
|
|
|
{
|
|
|
|
|
private static readonly string clearMigration =
|
2021-04-04 18:49:04 +04:00
|
|
|
|
@"DELETE FROM [DepartmentDatabasePortal].[dbo].[EnviromentSettings];
|
2021-03-26 20:09:52 +04:00
|
|
|
|
GO
|
2021-04-04 18:49:04 +04:00
|
|
|
|
DELETE FROM [DepartmentDatabasePortal].[dbo].[Accesses];
|
2021-03-26 20:09:52 +04:00
|
|
|
|
GO
|
2021-04-04 18:49:04 +04:00
|
|
|
|
DELETE FROM [DepartmentDatabasePortal].[dbo].[UserRoles];
|
2021-03-26 20:09:52 +04:00
|
|
|
|
GO
|
2021-04-04 18:49:04 +04:00
|
|
|
|
DELETE FROM [DepartmentDatabasePortal].[dbo].[Users];
|
2021-03-26 20:09:52 +04:00
|
|
|
|
GO
|
2021-04-04 18:49:04 +04:00
|
|
|
|
DELETE FROM [DepartmentDatabasePortal].[dbo].[Roles];
|
2021-03-26 20:09:52 +04:00
|
|
|
|
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 =
|
2021-04-02 20:04:46 +04:00
|
|
|
|
@"INSERT INTO DepartmentDatabasePortal.dbo.Users(Id, UserName, PasswordHash, Avatar, DateLastVisit, IsBanned, DateBanned, CountAttempt, DateCreate, DateDelete, IsDeleted)
|
|
|
|
|
SELECT Id, UserName, PasswordHash, Avatar, DateLastVisit, IsLocked, DateBanned, CountAttempt, DateCreate, DateDelete, IsDeleted FROM DepartmentDatabaseContext.dbo.DepartmentUsers";
|
2021-03-26 20:09:52 +04:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|