2021-04-04 18:49:04 +04:00
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
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 ] ;
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 ] = ' 4581 ADC8 - 5 A15 - 4F 95 - A40D - 1607856 ACB5C ' OR [ Id ] = ' 9D A4D810 - 025 A - 4 A03 - 81F D - 293D EF52FA4B ' - - д у б л т в д и с ц и п д и н а х
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 =
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-05 12:25:10 +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
/// <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 ) ;
}
}
}