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

68 lines
4.0 KiB
C#
Raw Normal View History

using Microsoft.EntityFrameworkCore;
namespace DatabaseCore.Scripts
{
/// <summary>
/// Скрипты для миграции данных по кафедре
/// </summary>
public static class DepartmentMigrationScript
{
private static readonly string clearMigration =
@"DELETE FROM [DepartmentDatabasePortal].[dbo].[Classrooms];
GO
DELETE FROM [DepartmentDatabasePortal].[dbo].[DisciplineBlocks];
GO
DELETE FROM [DepartmentDatabasePortal].[dbo].[Disciplines];
GO
DELETE FROM [DepartmentDatabasePortal].[dbo].[LecturerPosts];
GO
DELETE FROM [DepartmentDatabasePortal].[dbo].[Lecturers];
GO";
private static readonly string classroomsMigration =
@"DECLARE @employeeId uniqueidentifier;
SELECT @employeeId = emp.[Id] FROM [DepartmentDatabasePortal].[dbo].[Employees] emp
INSERT INTO [DepartmentDatabasePortal].[dbo].[Classrooms]([Id],[Number],[EmployeeId],[ClassroomType],[Square],[Capacity],[HaveProjector],[SecurityCode],[DateCreate],[DateDelete],[IsDeleted])
SELECT [Id],[Number],@employeeId,[ClassroomType],1,[Capacity],0,'-',[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[Classrooms]";
private static readonly string disciplineBlockMigration =
@"INSERT INTO [DepartmentDatabasePortal].[dbo].[DisciplineBlocks]([Id],[Title],[DisciplineBlockUseForGrouping],[DisciplineBlockOrder],[DisciplineBlockBlueAsteriskName],[DateCreate],[DateDelete],[IsDeleted])
SELECT [Id],[Title],[DisciplineBlockUseForGrouping],[DisciplineBlockOrder],[DisciplineBlockBlueAsteriskName],[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[DisciplineBlocks]";
private static readonly string disciplineMigration =
@"DELETE FROM [DepartmentDatabaseContext].[dbo].[Disciplines] WHERE [Id]='6CC684D5-900C-4278-AA43-0B83D0711C55' OR [Id]='A6598227-8449-4884-8290-13EABEC26924'
OR [Id]='4581ADC8-5A15-4F95-A40D-1607856ACB5C' OR [Id]='9DA4D810-025A-4A03-81FD-293DEF52FA4B' -- дублт в дисципдинах
INSERT INTO [DepartmentDatabasePortal].[dbo].[Disciplines]([Id],[DisciplineBlockId],[DisciplineName],[DisciplineShortName],[Description],[DisciplineBlueAsteriskName],[DateCreate],[DateDelete],[IsDeleted])
SELECT [Id],[DisciplineBlockId],[DisciplineName],[DisciplineShortName],[DisciplineDescription],[DisciplineBlueAsteriskName],[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[Disciplines]";
private static readonly string lecturerpostMigration =
@"INSERT INTO [DepartmentDatabasePortal].[dbo].[LecturerPosts]([Id],[LecturerPostName],[Hours],[Order],[DateCreate],[DateDelete],[IsDeleted])
SELECT [Id],[StudyPostTitle],[Hours],1,[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[LecturerStudyPosts]";
private static readonly string lecturerMigration =
@"DECLARE @userId uniqueidentifier;
SELECT @userId = u.[Id] FROM [DepartmentDatabasePortal].[dbo].[Users] u WHERE u.[UserName]='admin'
INSERT INTO [DepartmentDatabasePortal].[dbo].[Lecturers]([Id],[UserId],[LecturerPostId],[LecturerPostRate],[LastName],[FirstName],[Patronymic],[Abbreviation],[DateBirth],[Address],[Email],[MobileNumber],[HomeNumber],[Description],[Photo],[GroupElectricalSafety],[OnlyForPrivate],[DateCreate],[DateDelete],[IsDeleted])
SELECT [Id],@userId,[LecturerStudyPostId],1,[LastName],[FirstName],[Patronymic],[Abbreviation],[DateBirth],[Address],[Email],[MobileNumber],[HomeNumber],[Description],[Photo],'I',[OnlyForPrivate],[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[Lecturers]";
/// <summary>
/// Перенос данных по безопасности
/// </summary>
/// <param name="context"></param>
public static void RunScript(DbContext context)
{
context.Database.ExecuteSqlRaw(clearMigration, null);
context.Database.ExecuteSqlRaw(classroomsMigration, null);
context.Database.ExecuteSqlRaw(disciplineBlockMigration, null);
context.Database.ExecuteSqlRaw(disciplineMigration, null);
context.Database.ExecuteSqlRaw(lecturerpostMigration, null);
context.Database.ExecuteSqlRaw(lecturerMigration, null);
}
}
}