2021-04-04 18:49:04 +04:00
using Microsoft.EntityFrameworkCore ;
2022-03-18 22:55:48 +04:00
namespace CoreDatabase.Scripts
2021-04-04 18:49:04 +04:00
{
/// <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
2021-04-05 12:25:10 +04:00
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ Posts ] ;
2021-04-04 18:49:04 +04:00
GO
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ Lecturers ] ;
2021-04-06 22:07:11 +04:00
GO
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ TimeNorms ] ;
GO
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ AcademicPlans ] ;
GO
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ AcademicPlanRecords ] ;
GO
DELETE FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ AcademicPlanRecordTimeNormHours ] ;
2021-04-04 18:49:04 +04:00
GO ";
private static readonly string classroomsMigration =
@ "DECLARE @employeeId uniqueidentifier;
SELECT @employeeId = emp . [ Id ] FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ Employees ] emp
2021-04-06 22:07:11 +04:00
INSERT INTO [ DepartmentDatabasePortal ] . [ dbo ] . [ Classrooms ] ( [ Id ] , [ Number ] , [ EmployeeId ] , [ ClassroomType ] , [ Square ] , [ Capacity ] , [ HaveProjector ] , [ SecurityCode ] ,
[DateCreate] , [ DateDelete ] , [ IsDeleted ] )
2021-04-04 18:49:04 +04:00
SELECT [ Id ] , [ Number ] , @employeeId , [ ClassroomType ] , 1 , [ Capacity ] , 0 , '-' , [ DateCreate ] , [ DateDelete ] , [ IsDeleted ] FROM [ DepartmentDatabaseContext ] . [ dbo ] . [ Classrooms ] ";
private static readonly string disciplineBlockMigration =
2021-04-06 22:07:11 +04:00
@ "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 ] ";
2021-04-04 18:49:04 +04:00
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 ] = ' 4581 ADC8 - 5 A15 - 4F 95 - A40D - 1607856 ACB5C ' OR [ Id ] = ' 9D A4D810 - 025 A - 4 A03 - 81F D - 293D EF52FA4B ' - - д у б л т в д и с ц и п д и н а х
2021-04-06 22:07:11 +04:00
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 ] ";
2021-04-04 18:49:04 +04:00
2021-04-05 14:20:07 +04:00
private static readonly string postMigration =
2021-04-05 12:25:10 +04:00
@ "INSERT INTO [DepartmentDatabasePortal].[dbo].[Posts]([Id],[PostName],[Hours],[Order],[DateCreate],[DateDelete],[IsDeleted])
2021-04-04 18:49:04 +04:00
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 '
2021-04-06 22:07:11 +04:00
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 ] ";
2021-04-04 18:49:04 +04:00
2021-04-05 14:20:07 +04:00
private static readonly string educationdirectionrMigration =
@ "DECLARE @lecturerId uniqueidentifier;
SELECT @lecturerId = l . [ Id ] FROM [ DepartmentDatabasePortal ] . [ dbo ] . [ Lecturers ] l
2021-04-06 22:07:11 +04:00
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 ] ";
private static readonly string timeNormMigration =
@ "INSERT INTO [DepartmentDatabasePortal].[dbo].[TimeNorms]([Id],[DisciplineBlockId],[TimeNormName],[TimeNormShortName]
, [ TimeNormOrder ] , [ TimeNormEducationDirectionQualification ] , [ KindOfLoadName ] , [ KindOfLoadAttributeName ] , [ KindOfLoadBlueAsteriskName ]
, [ KindOfLoadBlueAsteriskAttributeName ] , [ KindOfLoadBlueAsteriskPracticName ] , [ UseInLearningProgress ] , [ UseInSite ] , [ DateCreate ] , [ DateDelete ] , [ IsDeleted ] )
SELECT [ Id ] , [ DisciplineBlockId ] , [ TimeNormName ] , [ TimeNormShortName ] , [ TimeNormOrder ] , [ TimeNormEducationDirectionQualification ] , [ KindOfLoadName ]
, [ KindOfLoadAttributeName ] , [ KindOfLoadBlueAsteriskName ] , [ KindOfLoadBlueAsteriskAttributeName ] , [ KindOfLoadBlueAsteriskPracticName ]
, [ UseInLearningProgress ] , [ UseInSite ] , [ DateCreate ] , [ DateDelete ] , [ IsDeleted ] FROM [ DepartmentDatabaseContext ] . [ dbo ] . [ TimeNorms ] WHERE
[AcademicYearId] = ' 4F FC16B7 - C1A5 - 47 B1 - B780 - 821 ED70793DC ' ";
private static readonly string academicplanMigration =
@ "INSERT INTO [DepartmentDatabasePortal].[dbo].[AcademicPlans]([Id],[EducationDirectionId],[YearEntrance],[YearFinish],[DateCreate],[DateDelete],[IsDeleted])
SELECT [ Id ] , [ EducationDirectionId ] , 2020 + ABS ( CHECKSUM ( NEWID ( ) ) % 100 ) , 2024 , [ DateCreate ] , [ DateDelete ] , [ IsDeleted ] FROM [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlans ] WHERE
[AcademicYearId] = ' 4F FC16B7 - C1A5 - 47 B1 - B780 - 821 ED70793DC ' ";
private static readonly string academicplanrecordsMigration =
@ "INSERT INTO [DepartmentDatabasePortal].[dbo].[AcademicPlanRecords]([Id],[AcademicPlanId],[DisciplineId],[InDepartment],[Semester],[Zet]
, [ AcademicPlanRecordParentId ] , [ IsParent ] , [ IsFacultative ] , [ DateCreate ] , [ DateDelete ] , [ IsDeleted ] )
SELECT apr . [ Id ] , apr . [ AcademicPlanId ] , apr . [ DisciplineId ] , apr . [ InDepartment ] , apr . [ Semester ] , apr . [ Zet ] , apr . [ AcademicPlanRecordParentId ] , apr . [ IsParent ] , apr . [ IsFacultative ]
, apr . [ DateCreate ] , apr . [ DateDelete ] , apr . [ IsDeleted ] FROM [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlanRecords ] apr
JOIN [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlans ] ap on apr . [ AcademicPlanId ] = ap . [ Id ] WHERE
ap . [ AcademicYearId ] = ' 4F FC16B7 - C1A5 - 47 B1 - B780 - 821 ED70793DC ' ";
private static readonly string academicplanrecordhoursMigration =
@ "INSERT INTO [DepartmentDatabasePortal].[dbo].[AcademicPlanRecordTimeNormHours]([Id],[AcademicPlanRecordId],[TimeNormId],[PlanHours],[DateCreate],[DateDelete],
[IsDeleted] )
SELECT apre . [ Id ] , apre . [ AcademicPlanRecordId ] , apre . [ TimeNormId ] , apre . [ PlanHours ] , apre . [ DateCreate ] , apre . [ DateDelete ] , apre . [ IsDeleted ]
FROM [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlanRecordElements ] apre
JOIN [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlanRecords ] apr on apre . [ AcademicPlanRecordId ] = apr . [ Id ]
JOIN [ DepartmentDatabaseContext ] . [ dbo ] . [ AcademicPlans ] ap on apr . [ AcademicPlanId ] = ap . [ Id ] WHERE
ap . [ AcademicYearId ] = ' 4F FC16B7 - C1A5 - 47 B1 - B780 - 821 ED70793DC ' ";
2021-04-05 14:20:07 +04:00
2021-04-04 18:49:04 +04:00
/// <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 ) ;
2021-04-05 14:20:07 +04:00
context . Database . ExecuteSqlRaw ( postMigration , null ) ;
2021-04-04 18:49:04 +04:00
context . Database . ExecuteSqlRaw ( lecturerMigration , null ) ;
2021-04-05 14:20:07 +04:00
context . Database . ExecuteSqlRaw ( educationdirectionrMigration , null ) ;
2021-04-06 22:07:11 +04:00
context . Database . ExecuteSqlRaw ( timeNormMigration , null ) ;
context . Database . ExecuteSqlRaw ( academicplanMigration , null ) ;
context . Database . ExecuteSqlRaw ( academicplanrecordsMigration , null ) ;
context . Database . ExecuteSqlRaw ( academicplanrecordhoursMigration , null ) ;
2021-04-04 18:49:04 +04:00
}
}
}