using System; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace TeleWave.Infrastructure.Migrations { /// public partial class AddScheduleTemplate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.AddColumn( name: "DayStartTime", table: "Channels", type: "time without time zone", nullable: false, defaultValue: new TimeOnly(0, 0, 0)); migrationBuilder.AddColumn( name: "Number", table: "Channels", type: "integer", nullable: true); migrationBuilder.AddColumn( name: "TemplateId", table: "Channels", type: "uuid", nullable: true); migrationBuilder.AddColumn( name: "UtcOffsetMinutes", table: "Channels", type: "integer", nullable: false, defaultValue: 0); migrationBuilder.CreateTable( name: "ScheduleTemplates", columns: table => new { Id = table.Column(type: "uuid", nullable: false), ChannelId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), FallbackGroupId = table.Column(type: "uuid", nullable: true), Revision = table.Column(type: "integer", nullable: false), AppliedRevision = table.Column(type: "integer", nullable: false), CreatedAt = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { table.PrimaryKey("PK_ScheduleTemplates", x => x.Id); }); migrationBuilder.CreateTable( name: "GridLayers", columns: table => new { Id = table.Column(type: "uuid", nullable: false), TemplateId = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "character varying(128)", maxLength: 128, nullable: false), Priority = table.Column(type: "integer", nullable: false), ApplicabilityJson = table.Column(type: "jsonb", nullable: true), IsEnabled = table.Column(type: "boolean", nullable: false), IsBackground = table.Column(type: "boolean", nullable: false) }, constraints: table => { table.PrimaryKey("PK_GridLayers", x => x.Id); table.ForeignKey( name: "FK_GridLayers_ScheduleTemplates_TemplateId", column: x => x.TemplateId, principalTable: "ScheduleTemplates", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Slots", columns: table => new { Id = table.Column(type: "uuid", nullable: false), LayerId = table.Column(type: "uuid", nullable: false), Weekday = table.Column(type: "integer", nullable: true), TargetStart = table.Column(type: "time without time zone", nullable: false), TargetDurationMinutes = table.Column(type: "integer", nullable: false), Title = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), Daypart = table.Column(type: "integer", nullable: false), SlotKind = table.Column(type: "integer", nullable: false), GroupId = table.Column(type: "uuid", nullable: true), StrategyJson = table.Column(type: "jsonb", nullable: true), RepeatSourceJson = table.Column(type: "jsonb", nullable: true), BlockMode = table.Column(type: "integer", nullable: false), BlockValue = table.Column(type: "integer", nullable: false), OverflowPolicy = table.Column(type: "integer", nullable: false), IsAnchor = table.Column(type: "boolean", nullable: false), MaxDriftMinutes = table.Column(type: "integer", nullable: false), SnapToMinutes = table.Column(type: "integer", nullable: true) }, constraints: table => { table.PrimaryKey("PK_Slots", x => x.Id); table.ForeignKey( name: "FK_Slots_GridLayers_LayerId", column: x => x.LayerId, principalTable: "GridLayers", principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Slots_Groups_GroupId", column: x => x.GroupId, principalTable: "Groups", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateTable( name: "SlotStates", columns: table => new { SlotId = table.Column(type: "uuid", nullable: false), CurrentElementKind = table.Column(type: "integer", nullable: true), CurrentElementId = table.Column(type: "uuid", nullable: true), NextUnitIndex = table.Column(type: "integer", nullable: false) }, constraints: table => { table.PrimaryKey("PK_SlotStates", x => x.SlotId); table.ForeignKey( name: "FK_SlotStates_Slots_SlotId", column: x => x.SlotId, principalTable: "Slots", principalColumn: "Id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "IX_Channels_Number", table: "Channels", column: "Number", unique: true, filter: "\"Number\" IS NOT NULL"); migrationBuilder.CreateIndex( name: "IX_GridLayers_TemplateId_Priority", table: "GridLayers", columns: new[] { "TemplateId", "Priority" }); migrationBuilder.CreateIndex( name: "IX_ScheduleTemplates_ChannelId", table: "ScheduleTemplates", column: "ChannelId"); migrationBuilder.CreateIndex( name: "IX_Slots_GroupId", table: "Slots", column: "GroupId"); migrationBuilder.CreateIndex( name: "IX_Slots_LayerId_TargetStart", table: "Slots", columns: new[] { "LayerId", "TargetStart" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "SlotStates"); migrationBuilder.DropTable( name: "Slots"); migrationBuilder.DropTable( name: "GridLayers"); migrationBuilder.DropTable( name: "ScheduleTemplates"); migrationBuilder.DropIndex( name: "IX_Channels_Number", table: "Channels"); migrationBuilder.DropColumn( name: "DayStartTime", table: "Channels"); migrationBuilder.DropColumn( name: "Number", table: "Channels"); migrationBuilder.DropColumn( name: "TemplateId", table: "Channels"); migrationBuilder.DropColumn( name: "UtcOffsetMinutes", table: "Channels"); } } }