using System; using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Migrations; namespace Cicm.Database.Migrations { public partial class AddOwnedMachines : Migration { protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable("OwnedMachines", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), AcquisitionDate = table.Column(), LostDate = table.Column(nullable: true), Status = table.Column(), LastStatusDate = table.Column(nullable: true), Trade = table.Column(), Boxed = table.Column(), Manuals = table.Column(), SerialNumber = table.Column(nullable: true), SerialNumberVisible = table.Column(nullable: false, defaultValue: true), MachineId = table.Column(), UserId = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_OwnedMachines", x => x.Id); table.ForeignKey("FK_OwnedMachines_machines_MachineId", x => x.MachineId, "machines", "id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_OwnedMachines_AspNetUsers_UserId", x => x.UserId, "AspNetUsers", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("GpusByOwnedMachine", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), GpuId = table.Column(), OwnedMachineId = table.Column() }, constraints: table => { table.PrimaryKey("PK_GpusByOwnedMachine", x => x.Id); table.ForeignKey("FK_GpusByOwnedMachine_gpus_GpuId", x => x.GpuId, "gpus", "id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_GpusByOwnedMachine_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("MemoryByOwnedMachine", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), OwnedMachineId = table.Column(), Type = table.Column(), Usage = table.Column(), Size = table.Column(), Speed = table.Column() }, constraints: table => { table.PrimaryKey("PK_MemoryByOwnedMachine", x => x.Id); table.ForeignKey("FK_MemoryByOwnedMachine_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("OwnedMachinePhotos", table => new { Id = table.Column(), Author = table.Column(nullable: true), CameraManufacturer = table.Column(nullable: true), CameraModel = table.Column(nullable: true), ColorSpace = table.Column(nullable: true), Comments = table.Column(nullable: true), Contrast = table.Column(nullable: true), CreationDate = table.Column(nullable: true), DigitalZoomRatio = table.Column(nullable: true), ExifVersion = table.Column(nullable: true), Exposure = table.Column(nullable: true), ExposureMethod = table.Column(nullable: true), ExposureProgram = table.Column(nullable: true), Flash = table.Column(nullable: true), Focal = table.Column(nullable: true), FocalLength = table.Column(nullable: true), FocalLengthEquivalent = table.Column(nullable: true), HorizontalResolution = table.Column(nullable: true), IsoRating = table.Column(nullable: true), Lens = table.Column(nullable: true), LightSource = table.Column(nullable: true), MeteringMode = table.Column(nullable: true), ResolutionUnit = table.Column(nullable: true), Orientation = table.Column(nullable: true), Saturation = table.Column(nullable: true), SceneCaptureType = table.Column(nullable: true), SensingMethod = table.Column(nullable: true), Sharpness = table.Column(nullable: true), SoftwareUsed = table.Column(nullable: true), SubjectDistanceRange = table.Column(nullable: true), UploadDate = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.ComputedColumn), VerticalResolution = table.Column(nullable: true), WhiteBalance = table.Column(nullable: true), UserId = table.Column(nullable: true), LicenseId = table.Column(), OwnedMachineId = table.Column() }, constraints: table => { table.PrimaryKey("PK_OwnedMachinePhotos", x => x.Id); table.ForeignKey("FK_OwnedMachinePhotos_Licenses_LicenseId", x => x.LicenseId, "Licenses", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_OwnedMachinePhotos_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_OwnedMachinePhotos_AspNetUsers_UserId", x => x.UserId, "AspNetUsers", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("ProcessorsByOwnedMachine", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), ProcessorId = table.Column(), OwnedMachineId = table.Column(), Speed = table.Column() }, constraints: table => { table.PrimaryKey("PK_ProcessorsByOwnedMachine", x => x.Id); table .ForeignKey("FK_ProcessorsByOwnedMachine_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_ProcessorsByOwnedMachine_processors_ProcessorId", x => x.ProcessorId, "processors", "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("SoundByOwnedMachine", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), SoundSynthId = table.Column(), OwnedMachineId = table.Column() }, constraints: table => { table.PrimaryKey("PK_SoundByOwnedMachine", x => x.Id); table.ForeignKey("FK_SoundByOwnedMachine_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey("FK_SoundByOwnedMachine_sound_synths_SoundSynthId", x => x.SoundSynthId, "sound_synths", "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable("StorageByOwnedMachine", table => new { Id = table.Column() .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), OwnedMachineId = table.Column(), Type = table.Column(), Interface = table.Column(), Capacity = table.Column() }, constraints: table => { table.PrimaryKey("PK_StorageByOwnedMachine", x => x.Id); table.ForeignKey("FK_StorageByOwnedMachine_OwnedMachines_OwnedMachineId", x => x.OwnedMachineId, "OwnedMachines", "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex("IX_GpusByOwnedMachine_GpuId", "GpusByOwnedMachine", "GpuId"); migrationBuilder.CreateIndex("IX_GpusByOwnedMachine_OwnedMachineId", "GpusByOwnedMachine", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_MemoryByOwnedMachine_OwnedMachineId", "MemoryByOwnedMachine", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_MemoryByOwnedMachine_Size", "MemoryByOwnedMachine", "Size"); migrationBuilder.CreateIndex("IX_MemoryByOwnedMachine_Speed", "MemoryByOwnedMachine", "Speed"); migrationBuilder.CreateIndex("IX_MemoryByOwnedMachine_Type", "MemoryByOwnedMachine", "Type"); migrationBuilder.CreateIndex("IX_MemoryByOwnedMachine_Usage", "MemoryByOwnedMachine", "Usage"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Author", "OwnedMachinePhotos", "Author"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_CameraManufacturer", "OwnedMachinePhotos", "CameraManufacturer"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_CameraModel", "OwnedMachinePhotos", "CameraModel"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_ColorSpace", "OwnedMachinePhotos", "ColorSpace"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Comments", "OwnedMachinePhotos", "Comments"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Contrast", "OwnedMachinePhotos", "Contrast"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_CreationDate", "OwnedMachinePhotos", "CreationDate"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_DigitalZoomRatio", "OwnedMachinePhotos", "DigitalZoomRatio"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_ExifVersion", "OwnedMachinePhotos", "ExifVersion"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Exposure", "OwnedMachinePhotos", "Exposure"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_ExposureMethod", "OwnedMachinePhotos", "ExposureMethod"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_ExposureProgram", "OwnedMachinePhotos", "ExposureProgram"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Flash", "OwnedMachinePhotos", "Flash"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Focal", "OwnedMachinePhotos", "Focal"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_FocalLength", "OwnedMachinePhotos", "FocalLength"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_FocalLengthEquivalent", "OwnedMachinePhotos", "FocalLengthEquivalent"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_HorizontalResolution", "OwnedMachinePhotos", "HorizontalResolution"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_IsoRating", "OwnedMachinePhotos", "IsoRating"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Lens", "OwnedMachinePhotos", "Lens"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_LicenseId", "OwnedMachinePhotos", "LicenseId"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_LightSource", "OwnedMachinePhotos", "LightSource"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_MeteringMode", "OwnedMachinePhotos", "MeteringMode"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Orientation", "OwnedMachinePhotos", "Orientation"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_OwnedMachineId", "OwnedMachinePhotos", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_ResolutionUnit", "OwnedMachinePhotos", "ResolutionUnit"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Saturation", "OwnedMachinePhotos", "Saturation"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_SceneCaptureType", "OwnedMachinePhotos", "SceneCaptureType"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_SensingMethod", "OwnedMachinePhotos", "SensingMethod"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_Sharpness", "OwnedMachinePhotos", "Sharpness"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_SoftwareUsed", "OwnedMachinePhotos", "SoftwareUsed"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_SubjectDistanceRange", "OwnedMachinePhotos", "SubjectDistanceRange"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_UploadDate", "OwnedMachinePhotos", "UploadDate"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_UserId", "OwnedMachinePhotos", "UserId"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_VerticalResolution", "OwnedMachinePhotos", "VerticalResolution"); migrationBuilder.CreateIndex("IX_OwnedMachinePhotos_WhiteBalance", "OwnedMachinePhotos", "WhiteBalance"); migrationBuilder.CreateIndex("IX_OwnedMachines_AcquisitionDate", "OwnedMachines", "AcquisitionDate"); migrationBuilder.CreateIndex("IX_OwnedMachines_Boxed", "OwnedMachines", "Boxed"); migrationBuilder.CreateIndex("IX_OwnedMachines_LastStatusDate", "OwnedMachines", "LastStatusDate"); migrationBuilder.CreateIndex("IX_OwnedMachines_LostDate", "OwnedMachines", "LostDate"); migrationBuilder.CreateIndex("IX_OwnedMachines_MachineId", "OwnedMachines", "MachineId"); migrationBuilder.CreateIndex("IX_OwnedMachines_Manuals", "OwnedMachines", "Manuals"); migrationBuilder.CreateIndex("IX_OwnedMachines_SerialNumber", "OwnedMachines", "SerialNumber"); migrationBuilder.CreateIndex("IX_OwnedMachines_SerialNumberVisible", "OwnedMachines", "SerialNumberVisible"); migrationBuilder.CreateIndex("IX_OwnedMachines_Status", "OwnedMachines", "Status"); migrationBuilder.CreateIndex("IX_OwnedMachines_Trade", "OwnedMachines", "Trade"); migrationBuilder.CreateIndex("IX_OwnedMachines_UserId", "OwnedMachines", "UserId"); migrationBuilder.CreateIndex("IX_ProcessorsByOwnedMachine_OwnedMachineId", "ProcessorsByOwnedMachine", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_ProcessorsByOwnedMachine_ProcessorId", "ProcessorsByOwnedMachine", "ProcessorId"); migrationBuilder.CreateIndex("IX_ProcessorsByOwnedMachine_Speed", "ProcessorsByOwnedMachine", "Speed"); migrationBuilder.CreateIndex("IX_SoundByOwnedMachine_OwnedMachineId", "SoundByOwnedMachine", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_SoundByOwnedMachine_SoundSynthId", "SoundByOwnedMachine", "SoundSynthId"); migrationBuilder.CreateIndex("IX_StorageByOwnedMachine_Capacity", "StorageByOwnedMachine", "Capacity"); migrationBuilder.CreateIndex("IX_StorageByOwnedMachine_Interface", "StorageByOwnedMachine", "Interface"); migrationBuilder.CreateIndex("IX_StorageByOwnedMachine_OwnedMachineId", "StorageByOwnedMachine", "OwnedMachineId"); migrationBuilder.CreateIndex("IX_StorageByOwnedMachine_Type", "StorageByOwnedMachine", "Type"); migrationBuilder.Sql(@"SELECT Id INTO @userId FROM AspNetUsers LIMIT 1; INSERT INTO OwnedMachines (AcquisitionDate, Status, Trade, Boxed, Manuals, MachineId, UserId) SELECT a.date, a.status, a.trade, a.boxed, a.manuals, a.db_id, @userId FROM owned_computers AS a;"); migrationBuilder.DropTable("owned_computers"); migrationBuilder.Sql(@"SELECT Id INTO @userId FROM AspNetUsers LIMIT 1; INSERT INTO OwnedMachines (AcquisitionDate, Status, Trade, Boxed, Manuals, MachineId, UserId) SELECT a.date, a.status, a.trade, a.boxed, a.manuals, a.db_id + 356, @userId FROM owned_consoles AS a;"); migrationBuilder.DropTable("owned_consoles"); } protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable("GpusByOwnedMachine"); migrationBuilder.DropTable("MemoryByOwnedMachine"); migrationBuilder.DropTable("OwnedMachinePhotos"); migrationBuilder.DropTable("ProcessorsByOwnedMachine"); migrationBuilder.DropTable("SoundByOwnedMachine"); migrationBuilder.DropTable("StorageByOwnedMachine"); migrationBuilder.DropTable("OwnedMachines"); migrationBuilder.CreateTable("owned_computers", table => new { id = table.Column("int(11)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), boxed = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), cap1 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), cap2 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), cpu1 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), cpu2 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), date = table.Column("varchar(20)", nullable: false, defaultValueSql: "''"), db_id = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), disk1 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), disk2 = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), manuals = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), mhz1 = table.Column("decimal(10,0)", nullable: false, defaultValueSql: "'0'"), mhz2 = table.Column("decimal(10,0)", nullable: false, defaultValueSql: "'0'"), ram = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), rigid = table.Column("varchar(64)", nullable: false, defaultValueSql: "''"), status = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), trade = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), vram = table.Column("int(11)", nullable: false, defaultValueSql: "'0'") }, constraints: table => { table.PrimaryKey("PK_owned_computers", x => x.id); }); migrationBuilder.CreateTable("owned_consoles", table => new { id = table.Column("int(11)") .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), boxed = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), date = table.Column("char(20)", nullable: false, defaultValueSql: "''"), db_id = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), manuals = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), status = table.Column("int(11)", nullable: false, defaultValueSql: "'0'"), trade = table.Column("int(11)", nullable: false, defaultValueSql: "'0'") }, constraints: table => { table.PrimaryKey("PK_owned_consoles", x => x.id); }); migrationBuilder.CreateIndex("idx_owned_computers_boxed", "owned_computers", "boxed"); migrationBuilder.CreateIndex("idx_owned_computers_cap1", "owned_computers", "cap1"); migrationBuilder.CreateIndex("idx_owned_computers_cap2", "owned_computers", "cap2"); migrationBuilder.CreateIndex("idx_owned_computers_cpu1", "owned_computers", "cpu1"); migrationBuilder.CreateIndex("idx_owned_computers_cpu2", "owned_computers", "cpu2"); migrationBuilder.CreateIndex("idx_owned_computers_date", "owned_computers", "date"); migrationBuilder.CreateIndex("idx_owned_computers_db_id", "owned_computers", "db_id"); migrationBuilder.CreateIndex("idx_owned_computers_disk1", "owned_computers", "disk1"); migrationBuilder.CreateIndex("idx_owned_computers_disk2", "owned_computers", "disk2"); migrationBuilder.CreateIndex("idx_owned_computers_manuals", "owned_computers", "manuals"); migrationBuilder.CreateIndex("idx_owned_computers_mhz1", "owned_computers", "mhz1"); migrationBuilder.CreateIndex("idx_owned_computers_mhz2", "owned_computers", "mhz2"); migrationBuilder.CreateIndex("idx_owned_computers_ram", "owned_computers", "ram"); migrationBuilder.CreateIndex("idx_owned_computers_rigid", "owned_computers", "rigid"); migrationBuilder.CreateIndex("idx_owned_computers_status", "owned_computers", "status"); migrationBuilder.CreateIndex("idx_owned_computers_trade", "owned_computers", "trade"); migrationBuilder.CreateIndex("idx_owned_computers_vram", "owned_computers", "vram"); migrationBuilder.CreateIndex("idx_owned_consoles_boxed", "owned_consoles", "boxed"); migrationBuilder.CreateIndex("idx_owned_consoles_date", "owned_consoles", "date"); migrationBuilder.CreateIndex("idx_owned_consoles_db_id", "owned_consoles", "db_id"); migrationBuilder.CreateIndex("idx_owned_consoles_manuals", "owned_consoles", "manuals"); migrationBuilder.CreateIndex("idx_owned_consoles_status", "owned_consoles", "status"); migrationBuilder.CreateIndex("idx_owned_consoles_trade", "owned_consoles", "trade"); } } }