using Microsoft.EntityFrameworkCore; namespace DatabaseCore.Scripts { /// /// Скрипты для миграции данных по кафедре /// 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].[Posts]; 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 postMigration = @"INSERT INTO [DepartmentDatabasePortal].[dbo].[Posts]([Id],[PostName],[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],[LastName],[FirstName],[Patronymic],[Abbreviation],[DateBirth],[Address],[Email],[MobileNumber],[HomeNumber],[Description],[Photo],[GroupElectricalSafety],[OnlyForPrivate],[DateCreate],[DateDelete],[IsDeleted]) SELECT [Id],@userId,[LastName],[FirstName],[Patronymic],[Abbreviation],[DateBirth],[Address],[Email],[MobileNumber],[HomeNumber],[Description],[Photo],'I',[OnlyForPrivate],[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[Lecturers]"; private static readonly string educationdirectionrMigration = @"DECLARE @lecturerId uniqueidentifier; SELECT @lecturerId = l.[Id] FROM [DepartmentDatabasePortal].[dbo].[Lecturers] l INSERT INTO [DepartmentDatabasePortal].[dbo].[EducationDirections]([Id],[Cipher],[ShortName],[Title],[Profile],[Qualification],[LecturerId],[Description],[DateCreate],[DateDelete],[IsDeleted]) SELECT [Id],[Cipher],[ShortName],[Title],[Profile],[Qualification],@lecturerId,[Description],[DateCreate],[DateDelete],[IsDeleted] FROM [DepartmentDatabaseContext].[dbo].[EducationDirections]"; /// /// Перенос данных по безопасности /// /// 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(postMigration, null); context.Database.ExecuteSqlRaw(lecturerMigration, null); context.Database.ExecuteSqlRaw(educationdirectionrMigration, null); } } }