using System; using System.Text.Json; using Microsoft.EntityFrameworkCore.Migrations; #nullable disable namespace Tiku.Infrastructure.Persistence.Migrations { /// public partial class AddScorelineDynamicRecords : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) { migrationBuilder.CreateTable( name: "scoreline_fields", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), region_id = table.Column(type: "uuid", nullable: true), legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), field_key = table.Column(type: "character varying(64)", maxLength: 64, nullable: false), field_name = table.Column(type: "character varying(200)", maxLength: 200, nullable: false), field_type = table.Column(type: "character varying(32)", maxLength: 32, nullable: false), unit = table.Column(type: "character varying(32)", maxLength: 32, nullable: true), is_filter = table.Column(type: "boolean", nullable: false), is_required = table.Column(type: "boolean", nullable: false), is_visible = table.Column(type: "boolean", nullable: false), is_trend = table.Column(type: "boolean", nullable: false), options = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'[]'::jsonb"), placeholder = table.Column(type: "character varying(200)", maxLength: 200, nullable: true), description = table.Column(type: "character varying(1000)", maxLength: 1000, nullable: true), sort_order = table.Column(type: "integer", nullable: false), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { table.PrimaryKey("pk_scoreline_fields", x => x.id); table.UniqueConstraint("ak_scoreline_fields_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_scoreline_fields_regions_tenant_id_region_id", columns: x => new { x.tenant_id, x.region_id }, principalTable: "regions", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_scoreline_fields_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "scoreline_records", columns: table => new { id = table.Column(type: "uuid", nullable: false, defaultValueSql: "gen_random_uuid()"), region_id = table.Column(type: "uuid", nullable: true), school_id = table.Column(type: "uuid", nullable: true), major_id = table.Column(type: "uuid", nullable: true), legacy_id = table.Column(type: "character varying(64)", maxLength: 64, nullable: true), year = table.Column(type: "integer", nullable: false), school_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), major_name = table.Column(type: "character varying(300)", maxLength: 300, nullable: true), field_values = table.Column(type: "jsonb", nullable: false, defaultValueSql: "'{}'::jsonb"), tenant_id = table.Column(type: "uuid", nullable: false), created_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()"), updated_at = table.Column(type: "timestamp with time zone", nullable: false, defaultValueSql: "now()") }, constraints: table => { table.PrimaryKey("pk_scoreline_records", x => x.id); table.UniqueConstraint("ak_scoreline_records_tenant_id_id", x => new { x.tenant_id, x.id }); table.ForeignKey( name: "fk_scoreline_records_majors_tenant_id_major_id", columns: x => new { x.tenant_id, x.major_id }, principalTable: "majors", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_scoreline_records_regions_tenant_id_region_id", columns: x => new { x.tenant_id, x.region_id }, principalTable: "regions", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_scoreline_records_schools_tenant_id_school_id", columns: x => new { x.tenant_id, x.school_id }, principalTable: "schools", principalColumns: new[] { "tenant_id", "id" }, onDelete: ReferentialAction.Restrict); table.ForeignKey( name: "fk_scoreline_records_tenants_tenant_id", column: x => x.tenant_id, principalTable: "tenants", principalColumn: "id", onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( name: "ix_scoreline_fields_tenant_id_legacy_id", table: "scoreline_fields", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_scoreline_fields_tenant_id_region_id_field_key", table: "scoreline_fields", columns: new[] { "tenant_id", "region_id", "field_key" }, unique: true); migrationBuilder.CreateIndex( name: "ix_scoreline_fields_tenant_id_region_id_is_filter_sort_order", table: "scoreline_fields", columns: new[] { "tenant_id", "region_id", "is_filter", "sort_order" }); migrationBuilder.CreateIndex( name: "ix_scoreline_records_tenant_id_legacy_id", table: "scoreline_records", columns: new[] { "tenant_id", "legacy_id" }, unique: true); migrationBuilder.CreateIndex( name: "ix_scoreline_records_tenant_id_major_id", table: "scoreline_records", columns: new[] { "tenant_id", "major_id" }); migrationBuilder.CreateIndex( name: "ix_scoreline_records_tenant_id_region_id_school_id_major_id_ye~", table: "scoreline_records", columns: new[] { "tenant_id", "region_id", "school_id", "major_id", "year" }); migrationBuilder.CreateIndex( name: "ix_scoreline_records_tenant_id_school_id", table: "scoreline_records", columns: new[] { "tenant_id", "school_id" }); migrationBuilder.CreateIndex( name: "ix_scoreline_records_tenant_id_year", table: "scoreline_records", columns: new[] { "tenant_id", "year" }); } /// protected override void Down(MigrationBuilder migrationBuilder) { migrationBuilder.DropTable( name: "scoreline_fields"); migrationBuilder.DropTable( name: "scoreline_records"); } } }