| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using Microsoft.EntityFrameworkCore.Metadata; |
| | | 3 | | |
| | | 4 | | namespace OzonRepositories.Context; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Приводит EF-модель к фактической схеме боевой БД ST2. |
| | | 8 | | /// |
| | | 9 | | /// Историческая причина: почти вся схема создавалась не миграциями, а руками — |
| | | 10 | | /// скриптами из Scripts/Sql и runtime-DDL в сервисах. Там писали DATETIME, TEXT, |
| | | 11 | | /// VARCHAR(N), DECIMAL(18,4) и заводили индексы, о которых модель никогда не знала. |
| | | 12 | | /// EF по умолчанию выводит datetime(6), longtext и decimal(65,30), поэтому модель |
| | | 13 | | /// и прод разъехались на 139 колонок и 90 индексов, а сгенерированный из модели |
| | | 14 | | /// baseline не воспроизводил реальную схему. |
| | | 15 | | /// |
| | | 16 | | /// Здесь модель подгоняется под БД, а не наоборот: правки чисто модельные и ALTER-ов |
| | | 17 | | /// на боевых таблицах не требуют. Обратное направление (несколько мест, где БД была |
| | | 18 | | /// слабее модели) закрыто миграцией ReconcileProdSchema. |
| | | 19 | | /// |
| | | 20 | | /// Списки сняты из information_schema и должны со временем пустеть: новые колонки и |
| | | 21 | | /// индексы задавайте сразу в конфигурации сущности, сюда ничего не дописывайте. |
| | | 22 | | /// Полноту списков стережёт ProdSchemaAlignmentTests. |
| | | 23 | | /// </summary> |
| | | 24 | | internal static class ProdSchemaAlignment |
| | | 25 | | { |
| | 1428 | 26 | | internal sealed record LegacyIndex(string Table, string Name, bool IsUnique, params string[] Columns); |
| | | 27 | | |
| | | 28 | | /// <summary>Типы колонок, которые в БД отличаются от выводимых EF по умолчанию.</summary> |
| | 1 | 29 | | internal static readonly Dictionary<(string Table, string Column), string> ColumnTypes = new() |
| | 1 | 30 | | { |
| | 1 | 31 | | [("AssemblyListAccessKeys", "AllowedOzonClientIds")] = "varchar(1000)", |
| | 1 | 32 | | [("AssemblyListAccessKeys", "AllowedStatuses")] = "varchar(1000)", |
| | 1 | 33 | | [("AssemblyListAccessKeys", "AllowedWarehouses")] = "varchar(500)", |
| | 1 | 34 | | [("AssemblyListRunItems", "ImageUrl")] = "text", |
| | 1 | 35 | | [("AssemblyListRunItems", "LabelError")] = "text", |
| | 1 | 36 | | [("AssemblyListRunItems", "LabelUrl")] = "text", |
| | 1 | 37 | | [("AssemblyListRunItems", "OneCBalance")] = "decimal(18,3)", |
| | 1 | 38 | | [("AssemblyListRunItems", "OneCOtherStock")] = "text", |
| | 1 | 39 | | [("AssemblyListRunItems", "OneCReceiptDoc")] = "varchar(64)", |
| | 1 | 40 | | [("AssemblyListRunItems", "ProductName")] = "text", |
| | 1 | 41 | | [("AssemblyListRunItems", "SupplierName")] = "varchar(255)", |
| | 1 | 42 | | [("AssemblyListRuns", "ErrorMessage")] = "text", |
| | 1 | 43 | | [("BackgroundJobExecutions", "CompletedAt")] = "datetime", |
| | 1 | 44 | | [("BackgroundJobExecutions", "ErrorMessage")] = "text", |
| | 1 | 45 | | [("BackgroundJobExecutions", "ErrorStackTrace")] = "text", |
| | 1 | 46 | | [("BackgroundJobExecutions", "StartedAt")] = "datetime", |
| | 1 | 47 | | [("BackgroundJobSchedules", "CreatedAt")] = "datetime", |
| | 1 | 48 | | [("BackgroundJobSchedules", "LastRunTime")] = "datetime", |
| | 1 | 49 | | [("BackgroundJobSchedules", "NextRunTime")] = "datetime", |
| | 1 | 50 | | [("BackgroundJobSchedules", "UpdatedAt")] = "datetime", |
| | 1 | 51 | | [("BackgroundJobSteps", "CompletedAt")] = "datetime", |
| | 1 | 52 | | [("BackgroundJobSteps", "ErrorMessage")] = "text", |
| | 1 | 53 | | [("BackgroundJobSteps", "StartedAt")] = "datetime", |
| | 1 | 54 | | [("BackgroundOrderMatches", "CreatedAt")] = "datetime", |
| | 1 | 55 | | [("BackgroundReportLoads", "CreatedAt")] = "datetime", |
| | 1 | 56 | | [("BackgroundReportLoads", "ErrorMessage")] = "text", |
| | 1 | 57 | | [("BackgroundReportLoads", "FileUrl")] = "text", |
| | 1 | 58 | | [("BackgroundReportLoads", "ReportPeriodFrom")] = "datetime", |
| | 1 | 59 | | [("BackgroundReportLoads", "ReportPeriodTo")] = "datetime", |
| | 1 | 60 | | [("BackgroundTransactionResults", "CreatedAt")] = "datetime", |
| | 1 | 61 | | [("BackgroundTransactionResults", "ErrorMessage")] = "text", |
| | 1 | 62 | | [("BitrixStockArchiveExecutions", "CompletedAt")] = "datetime", |
| | 1 | 63 | | [("BitrixStockArchiveExecutions", "ErrorMessage")] = "text", |
| | 1 | 64 | | [("BitrixStockArchiveExecutions", "StartedAt")] = "datetime", |
| | 1 | 65 | | [("BitrixStockArchiveItems", "ErrorMessage")] = "text", |
| | 1 | 66 | | [("BitrixStockArchiveItems", "ProcessedAt")] = "datetime", |
| | 1 | 67 | | [("BitrixStockAutoScheduleRuns", "CompletedAt")] = "datetime", |
| | 1 | 68 | | [("BitrixStockAutoScheduleRuns", "ErrorMessage")] = "text", |
| | 1 | 69 | | [("BitrixStockAutoScheduleRuns", "RunLog")] = "text", |
| | 1 | 70 | | [("BitrixStockAutoScheduleRuns", "StartedAt")] = "datetime", |
| | 1 | 71 | | [("BitrixStockAutoSchedules", "CreatedAt")] = "datetime", |
| | 1 | 72 | | [("BitrixStockAutoSchedules", "LastRunAt")] = "datetime", |
| | 1 | 73 | | [("BitrixStockAutoSchedules", "NextRunAt")] = "datetime", |
| | 1 | 74 | | [("BitrixStockAutoSchedules", "UpdatedAt")] = "datetime", |
| | 1 | 75 | | [("BitrixStockClearExecutions", "CompletedAt")] = "datetime", |
| | 1 | 76 | | [("BitrixStockClearExecutions", "ErrorMessage")] = "text", |
| | 1 | 77 | | [("BitrixStockClearExecutions", "StartedAt")] = "datetime", |
| | 1 | 78 | | [("BitrixStockClearItems", "ErrorMessage")] = "text", |
| | 1 | 79 | | [("BitrixStockClearItems", "ProcessedAt")] = "datetime", |
| | 1 | 80 | | [("BitrixStockPushExecutions", "CompletedAt")] = "datetime", |
| | 1 | 81 | | [("BitrixStockPushExecutions", "ErrorMessage")] = "text", |
| | 1 | 82 | | [("BitrixStockPushExecutions", "StartedAt")] = "datetime", |
| | 1 | 83 | | [("BitrixStockPushItems", "ErrorMessage")] = "text", |
| | 1 | 84 | | [("BitrixStockPushItems", "ProcessedAt")] = "datetime", |
| | 1 | 85 | | [("BitrixStockSavedFilter", "CreatedAt")] = "datetime", |
| | 1 | 86 | | [("BitrixStockSavedFilter", "UpdatedAt")] = "datetime", |
| | 1 | 87 | | [("BitrixStockUnarchiveExecutions", "CompletedAt")] = "datetime", |
| | 1 | 88 | | [("BitrixStockUnarchiveExecutions", "ErrorMessage")] = "text", |
| | 1 | 89 | | [("BitrixStockUnarchiveExecutions", "StartedAt")] = "datetime", |
| | 1 | 90 | | [("BitrixStockUnarchiveItems", "ErrorMessage")] = "text", |
| | 1 | 91 | | [("BitrixStockUnarchiveItems", "ProcessedAt")] = "datetime", |
| | 1 | 92 | | [("ExcelMappings", "ColumnMappingsJson")] = "text", |
| | 1 | 93 | | [("ExcelMappings", "CreatedBy")] = "varchar(255)", |
| | 1 | 94 | | [("ExcelMappings", "CreatedDate")] = "datetime", |
| | 1 | 95 | | [("ExcelMappings", "ModifiedDate")] = "datetime", |
| | 1 | 96 | | [("FileUploadRecords", "Date")] = "datetime", |
| | 1 | 97 | | [("FileUploadRecords", "Result")] = "text", |
| | 1 | 98 | | [("ItemStatuses", "Name")] = "text", |
| | 1 | 99 | | [("MlAutoCartItems", "Quantity")] = "decimal(18,3)", |
| | 1 | 100 | | [("MlAutoCartItems", "SourcePrice")] = "decimal(18,4)", |
| | 1 | 101 | | [("MlAutoOrderItems", "Price")] = "decimal(18,4)", |
| | 1 | 102 | | [("MlAutoOrderItems", "Quantity")] = "decimal(18,3)", |
| | 1 | 103 | | [("MlAutoRuCartItems", "Quantity")] = "decimal(18,3)", |
| | 1 | 104 | | [("MlAutoRuCartItems", "SourcePrice")] = "decimal(18,4)", |
| | 1 | 105 | | [("MlAutoRuOrderItems", "Price")] = "decimal(18,4)", |
| | 1 | 106 | | [("MlAutoRuOrderItems", "Quantity")] = "decimal(18,3)", |
| | 1 | 107 | | [("OrderArchives", "ArchivedAt")] = "datetime", |
| | 1 | 108 | | [("OrderCarts", "CreatedAt")] = "datetime", |
| | 1 | 109 | | [("OrderExtraExpenses", "CreatedAt")] = "datetime", |
| | 1 | 110 | | [("OrderHistoryOneCPostings", "CreatedAt")] = "datetime", |
| | 1 | 111 | | [("OrderHistoryOneCPostings", "PostedAt")] = "datetime", |
| | 1 | 112 | | [("OrderReturns", "ProductCommission")] = "decimal(18,2)", |
| | 1 | 113 | | [("OrderReturns", "ProductPrice")] = "decimal(18,2)", |
| | 1 | 114 | | [("OrderReturns", "StorageSumPrice")] = "decimal(18,2)", |
| | 1 | 115 | | [("OrderReturns", "UtilizationSumPrice")] = "decimal(18,2)", |
| | 1 | 116 | | [("OrderShipmentTotals", "CreatedAt")] = "datetime", |
| | 1 | 117 | | [("OrderShipmentTotals", "UpdatedAt")] = "datetime", |
| | 1 | 118 | | [("Orders", "CostPrice")] = "decimal(65,2)", |
| | 1 | 119 | | [("Orders", "MaxDiscount")] = "decimal(65,2)", |
| | 1 | 120 | | [("Orders", "MaxOzonCommission")] = "decimal(65,2)", |
| | 1 | 121 | | [("Orders", "MaxProfit")] = "decimal(65,2)", |
| | 1 | 122 | | [("Orders", "MinDiscount")] = "decimal(65,2)", |
| | 1 | 123 | | [("Orders", "MinOzonCommission")] = "decimal(65,2)", |
| | 1 | 124 | | [("Orders", "MinProfit")] = "decimal(65,2)", |
| | 1 | 125 | | [("Orders", "OriginalPurchasePrice")] = "decimal(65,2)", |
| | 1 | 126 | | [("Orders", "Price")] = "decimal(65,2)", |
| | 1 | 127 | | [("Orders", "PurchasePrice")] = "decimal(65,2)", |
| | 1 | 128 | | [("Orders", "ShipmentAmount")] = "decimal(65,2)", |
| | 1 | 129 | | [("OzonChatOrders", "CreatedAt")] = "datetime", |
| | 1 | 130 | | [("OzonChatOrders", "LastMessageDate")] = "datetime", |
| | 1 | 131 | | [("OzonChatOrders", "UpdatedAt")] = "datetime", |
| | 1 | 132 | | [("OzonChatResponseTimes", "CreatedAt")] = "datetime", |
| | 1 | 133 | | [("OzonChatResponseTimes", "RecordedAt")] = "datetime", |
| | 1 | 134 | | [("OzonPostingCancellations", "ReasonMessage")] = "text", |
| | 1 | 135 | | [("PriceHistories", "Article")] = "varchar(100)", |
| | 1 | 136 | | [("PriceHistories", "Author")] = "varchar(100)", |
| | 1 | 137 | | [("PriceHistories", "CreateDateTime")] = "datetime", |
| | 1 | 138 | | [("PriceHistories", "Currency")] = "varchar(10)", |
| | 1 | 139 | | [("PriceHistories", "PriceValue")] = "decimal(18,2)", |
| | 1 | 140 | | [("PriceHistories", "RegistrationPrice")] = "decimal(18,2)", |
| | 1 | 141 | | [("PriceHistories", "ValueSource")] = "varchar(100)", |
| | 1 | 142 | | [("StatusTransitionHistory", "Comment")] = "text", |
| | 1 | 143 | | [("StatusTransitions", "Conditions")] = "text", |
| | 1 | 144 | | [("SupplierQuotationOffers", "SourcePrice")] = "decimal(18,4)", |
| | 1 | 145 | | [("Suppliers", "CsvUrl")] = "varchar(250)", |
| | 1 | 146 | | [("WarehouseMapping", "BitrixWarehouseName")] = "varchar(200)", |
| | 1 | 147 | | [("WarehouseMapping", "DeliveryType")] = "varchar(100)", |
| | 1 | 148 | | [("WarehouseMapping", "OzonWarehouseId")] = "varchar(32)", |
| | 1 | 149 | | [("WarehouseMapping", "OzonWarehouseName")] = "varchar(200)", |
| | 1 | 150 | | [("WarehouseMapping", "ReturnBitrixWarehouseName")] = "varchar(255)", |
| | 1 | 151 | | [("WarehouseMapping", "TransitBitrixWarehouseName")] = "varchar(255)", |
| | 1 | 152 | | [("WarehouseStockSnapshot", "AccountingPriceUnit")] = "decimal(18,4)", |
| | 1 | 153 | | [("WarehouseStockSnapshot", "B1Qty")] = "decimal(18,4)", |
| | 1 | 154 | | [("WarehouseStockSnapshot", "B2Qty")] = "decimal(18,4)", |
| | 1 | 155 | | [("WarehouseStockSnapshot", "C0")] = "decimal(18,4)", |
| | 1 | 156 | | [("WarehouseStockSnapshot", "C1ExistMinus5Percent")] = "decimal(18,4)", |
| | 1 | 157 | | [("WarehouseStockSnapshot", "C1PercentToC0")] = "decimal(18,4)", |
| | 1 | 158 | | [("WarehouseStockSnapshot", "ExistPrice")] = "decimal(18,4)", |
| | 1 | 159 | | [("WarehouseStockSnapshot", "M1Qty")] = "decimal(18,4)", |
| | 1 | 160 | | [("WarehouseStockSnapshot", "M2Qty")] = "decimal(18,4)", |
| | 1 | 161 | | [("WarehouseStockSnapshot", "M3Qty")] = "decimal(18,4)", |
| | 1 | 162 | | [("WarehouseStockSnapshot", "PriceDiffAccountingMinusSale")] = "decimal(18,4)", |
| | 1 | 163 | | [("WarehouseStockSnapshot", "SalePriceUnit")] = "decimal(18,4)", |
| | 1 | 164 | | [("WarehouseStockSnapshot", "StockAmountByC0")] = "decimal(18,4)", |
| | 1 | 165 | | [("WarehouseStockSnapshot", "TotalCost")] = "decimal(18,4)", |
| | 1 | 166 | | [("WarehouseStockSnapshot", "UnitCost")] = "decimal(18,4)", |
| | 1 | 167 | | [("WarehouseStockSyncRuns", "ErrorMessage")] = "text", |
| | 1 | 168 | | [("order_extensions", "CreatedAt")] = "datetime", |
| | 1 | 169 | | [("orders_history", "NewValue")] = "text", |
| | 1 | 170 | | [("orders_history", "OldValue")] = "text", |
| | 1 | 171 | | }; |
| | | 172 | | |
| | | 173 | | /// <summary>Колонки, объявленные в БД как NOT NULL, но опциональные в модели.</summary> |
| | 1 | 174 | | internal static readonly HashSet<(string Table, string Column)> RequiredColumns = new() |
| | 1 | 175 | | { |
| | 1 | 176 | | ("ExcludedWarehouses", "Name"), |
| | 1 | 177 | | ("orders_history", "ColumnDisplayName"), |
| | 1 | 178 | | ("orders_history", "ColumnName"), |
| | 1 | 179 | | }; |
| | | 180 | | |
| | | 181 | | /// <summary> |
| | | 182 | | /// Имена индексов, которые на проде отличаются от выводимых EF. |
| | | 183 | | /// Ключ — таблица и колонки через запятую в порядке следования в индексе. |
| | | 184 | | /// Нужны, чтобы будущая миграция, удаляющая или переименовывающая индекс, |
| | | 185 | | /// обращалась к нему по тому имени, которое реально есть в боевой БД. |
| | | 186 | | /// </summary> |
| | 1 | 187 | | internal static readonly Dictionary<(string Table, string Columns), string> IndexNames = new() |
| | 1 | 188 | | { |
| | 1 | 189 | | [("order_extensions", "OrderId,Key")] = "UX_OrderExtensions_OrderId_Key", |
| | 1 | 190 | | [("ApiSupplierSettings", "ProviderKey")] = "UX_ApiSupplierSettings_ProviderKey", |
| | 1 | 191 | | [("AppStatuses", "StatusColorId")] = "FK_AppStatuses_StatusColors", |
| | 1 | 192 | | [("ArmtekCartItems", "ProviderKey,ActiveStudioOrderId")] = "UX_ArmtekCartItems_Provider_ActiveOrder", |
| | 1 | 193 | | [("ArmtekCartItems", "ProviderKey,CreatedAtUtc")] = "IX_ArmtekCartItems_Provider_Created", |
| | 1 | 194 | | [("ArmtekCartItems", "ProviderKey,StudioOrderId,Status")] = "IX_ArmtekCartItems_Provider_Order_Status", |
| | 1 | 195 | | [("ArmtekCartItems", "StudioOrderId")] = "FK_ArmtekCartItems_Orders_StudioOrderId", |
| | 1 | 196 | | [("ArmtekDeliveryAddressMappings", "ProviderKey,ShipmentWarehouseId")] = "UX_ArmtekDeliveryAddressMappings_Provi |
| | 1 | 197 | | [("ArmtekDeliveryAddressMappings", "ShipmentWarehouseId")] = "FK_ArmtekDeliveryAddressMappings_Warehouses_Shipme |
| | 1 | 198 | | [("ArmtekOrderItems", "ArmtekCartItemId")] = "FK_ArmtekOrderItems_ArmtekCartItems", |
| | 1 | 199 | | [("ArmtekOrderItems", "ArmtekOrderId")] = "IX_ArmtekOrderItems_Order", |
| | 1 | 200 | | [("ArmtekOrderItems", "StudioOrderId")] = "FK_ArmtekOrderItems_Orders_StudioOrderId", |
| | 1 | 201 | | [("ArmtekOrders", "ProviderKey,Vbeln")] = "UX_ArmtekOrders_Provider_Vbeln", |
| | 1 | 202 | | [("AssemblyListRunItems", "RunId")] = "idx_alri_run", |
| | 1 | 203 | | [("BackgroundJobSchedules", "OzonClientId")] = "fk_schedule_ozon_client", |
| | 1 | 204 | | [("BackgroundOrderMatches", "ExecutionId")] = "idx_execution", |
| | 1 | 205 | | [("BackgroundOrderMatches", "OrderId")] = "idx_order", |
| | 1 | 206 | | [("BackgroundOrderMatches", "ReportLoadId")] = "idx_report_load", |
| | 1 | 207 | | [("BackgroundOrderMatches", "StepId")] = "fk_match_step", |
| | 1 | 208 | | [("BackgroundReportLoads", "ExecutionId")] = "idx_execution", |
| | 1 | 209 | | [("BackgroundReportLoads", "OzonClientId")] = "idx_ozon_client", |
| | 1 | 210 | | [("BackgroundReportLoads", "StepId")] = "fk_report_step", |
| | 1 | 211 | | [("BackgroundTransactionResults", "ExecutionId")] = "idx_execution", |
| | 1 | 212 | | [("BackgroundTransactionResults", "OrderId")] = "idx_order", |
| | 1 | 213 | | [("BackgroundTransactionResults", "OrderMatchId")] = "idx_order_match", |
| | 1 | 214 | | [("BackgroundTransactionResults", "StepId")] = "fk_result_step", |
| | 1 | 215 | | [("BackgroundTransactionResults", "TransactionId")] = "idx_transaction", |
| | 1 | 216 | | [("BergCartItems", "ActiveStudioOrderId")] = "UX_BergCartItems_ActiveStudioOrderId", |
| | 1 | 217 | | [("BergCartItems", "CreatedAtUtc")] = "IX_BergCartItems_Created", |
| | 1 | 218 | | [("BergCartItems", "StudioOrderId,Status")] = "IX_BergCartItems_Order_Status", |
| | 1 | 219 | | [("BergDeliveryAddressMappings", "ShipmentWarehouseId")] = "UX_BergDeliveryAddressMappings_Warehouse", |
| | 1 | 220 | | [("BergOrderItems", "BergCartItemId")] = "IX_BergOrderItems_CartItem", |
| | 1 | 221 | | [("BergOrderItems", "BergOrderId")] = "IX_BergOrderItems_Order", |
| | 1 | 222 | | [("BergOrderItems", "StudioOrderId")] = "IX_BergOrderItems_StudioOrder", |
| | 1 | 223 | | [("BergOrders", "ExternalOrderId")] = "UX_BergOrders_ExternalOrderId", |
| | 1 | 224 | | [("BergOrders", "Reference")] = "UX_BergOrders_Reference", |
| | 1 | 225 | | [("ClientStatuses", "StatusColorId")] = "FK_clientstatuses_StatusColors_StatusColorId", |
| | 1 | 226 | | [("Deliveries", "ProviderId")] = "ProviderId", |
| | 1 | 227 | | [("EmailMessageInboxes", "MessageExternalId")] = "UX_EmailMessageInboxes_MessageExternalId", |
| | 1 | 228 | | [("FavoritPartsCartItems", "ProviderKey,ActiveStudioOrderId")] = "UX_FavoritPartsCartItems_Provider_ActiveOrder" |
| | 1 | 229 | | [("FavoritPartsCartItems", "ProviderKey,CreatedAtUtc")] = "IX_FavoritPartsCartItems_Provider_Created", |
| | 1 | 230 | | [("FavoritPartsCartItems", "ProviderKey,StudioOrderId,Status")] = "IX_FavoritPartsCartItems_Provider_Order_Statu |
| | 1 | 231 | | [("FavoritPartsCartItems", "StudioOrderId")] = "FK_FavoritPartsCartItems_Orders_StudioOrderId", |
| | 1 | 232 | | [("FavoritPartsOrderItems", "FavoritPartsCartItemId")] = "FK_FavoritPartsOrderItems_FavoritPartsCartItems", |
| | 1 | 233 | | [("FavoritPartsOrderItems", "FavoritPartsOrderId")] = "IX_FavoritPartsOrderItems_Order", |
| | 1 | 234 | | [("FavoritPartsOrderItems", "StudioOrderId")] = "FK_FavoritPartsOrderItems_Orders_StudioOrderId", |
| | 1 | 235 | | [("FavoritPartsOrders", "ProviderKey,ExternalOrderId")] = "UX_FavoritPartsOrders_Provider_ExternalOrderId", |
| | 1 | 236 | | [("FidSupplierLinks", "FidSupplierName")] = "UX_FidSupplierLinks_FidSupplierName", |
| | 1 | 237 | | [("ForumAutoCartItems", "ProviderKey,ActiveStudioOrderId")] = "UX_ForumAutoCartItems_Provider_ActiveOrder", |
| | 1 | 238 | | [("ForumAutoCartItems", "ProviderKey,CreatedAtUtc")] = "IX_ForumAutoCartItems_Provider_Created", |
| | 1 | 239 | | [("ForumAutoCartItems", "ProviderKey,StudioOrderId,Status")] = "IX_ForumAutoCartItems_Provider_Order_Status", |
| | 1 | 240 | | [("ForumAutoCartItems", "StudioOrderId")] = "FK_ForumAutoCartItems_Orders_StudioOrderId", |
| | 1 | 241 | | [("ForumAutoOrderItems", "ForumAutoCartItemId")] = "FK_ForumAutoOrderItems_ForumAutoCartItems", |
| | 1 | 242 | | [("ForumAutoOrderItems", "ForumAutoOrderId")] = "IX_ForumAutoOrderItems_Order", |
| | 1 | 243 | | [("ForumAutoOrderItems", "StudioOrderId")] = "FK_ForumAutoOrderItems_Orders_StudioOrderId", |
| | 1 | 244 | | [("ForumAutoOrders", "ProviderKey,Did")] = "UX_ForumAutoOrders_Provider_Did", |
| | 1 | 245 | | [("ForumAutoOrders", "ProviderKey,Eoid")] = "IX_ForumAutoOrders_Provider_Eoid", |
| | 1 | 246 | | [("InterpartsWarehouseLogins", "WarehouseId")] = "UX_InterpartsWarehouseLogins_WarehouseId", |
| | 1 | 247 | | [("ItemStatuses", "StatusColorId")] = "FK_ItemStatuses_StatusColors", |
| | 1 | 248 | | [("MikadoCartItems", "ActiveStudioOrderId")] = "UX_MikadoCartItems_ActiveStudioOrderId", |
| | 1 | 249 | | [("MikadoCartItems", "StudioOrderId")] = "FK_MikadoCartItems_Orders", |
| | 1 | 250 | | [("MlAutoDeliveryAddressMappings", "ShipmentWarehouseId")] = "UX_MlAutoDeliveryAddressMappings_Warehouse", |
| | 1 | 251 | | [("MlAutoOrderItems", "MlAutoOrderId")] = "IX_MlAutoOrderItems_Order", |
| | 1 | 252 | | [("MlAutoRuDeliveryAddressMappings", "ShipmentWarehouseId")] = "UX_MlAutoRuDeliveryAddressMappings_Warehouse", |
| | 1 | 253 | | [("MlAutoRuOrderItems", "MlAutoRuOrderId")] = "IX_MlAutoRuOrderItems_Order", |
| | 1 | 254 | | [("MoskvorechieIstraCartItems", "ActiveStudioOrderId")] = "UX_MoskvorechieIstraCartItems_ActiveStudioOrderId", |
| | 1 | 255 | | [("MoskvorechieIstraCartItems", "StudioOrderId")] = "FK_MoskvorechieIstraCartItems_StudioOrder", |
| | 1 | 256 | | [("MoskvorechieIstraOrderItems", "MoskvorechieIstraOrderId,StudioOrderId,Article")] = "UX_MoskvorechieIstraOrder |
| | 1 | 257 | | [("MoskvorechieIstraOrderItems", "StudioOrderId")] = "FK_MoskvorechieIstraOrderItems_StudioOrder", |
| | 1 | 258 | | [("MoskvorechieIstraOrders", "ExternalOrderNumber")] = "UX_MoskvorechieIstraOrders_ExternalOrderNumber", |
| | 1 | 259 | | [("MotexCartItems", "ActiveStudioOrderId")] = "UX_MotexCartItems_ActiveStudioOrderId", |
| | 1 | 260 | | [("MotexCartItems", "StudioOrderId,Status")] = "IX_MotexCartItems_StudioOrder_Status", |
| | 1 | 261 | | [("MotexOrderItems", "MotexOrderId,StudioOrderId,Code")] = "UX_MotexOrderItems_Order_StudioOrder_Code", |
| | 1 | 262 | | [("MotexOrders", "ClientOrderNum")] = "UX_MotexOrders_ClientOrderNum", |
| | 1 | 263 | | [("OrderArchives", "OrderId")] = "UK_OrderArchives_OrderId", |
| | 1 | 264 | | [("OrderCalculationSnapshots", "OrderId,OperationId")] = "UX_OrderCalculationSnapshots_OrderId_OperationId", |
| | 1 | 265 | | [("OrderCarts", "CartStatusId")] = "ix_ordercarts_cartstatusid", |
| | 1 | 266 | | [("OrderControlRules", "Code")] = "UX_OrderControlRules_Code", |
| | 1 | 267 | | [("OrderControlRules", "IsActive,RuleType")] = "IX_OrderControlRules_Active_Type", |
| | 1 | 268 | | [("OrderControlRules", "TargetAppRoleId")] = "FK_OrderControlRules_AppRoles_TargetAppRoleId", |
| | 1 | 269 | | [("OrderControlTasks", "DeduplicationKey")] = "UX_OrderControlTasks_DeduplicationKey", |
| | 1 | 270 | | [("OrderControlTasks", "OrderId")] = "FK_OrderControlTasks_Orders_OrderId", |
| | 1 | 271 | | [("OrderControlTasks", "RuleId")] = "FK_OrderControlTasks_OrderControlRules_RuleId", |
| | 1 | 272 | | [("OrderHistoryOneCPostingLinks", "PostingId,OrderHistoryId")] = "UX_OrderHistoryOneCPostingLinks", |
| | 1 | 273 | | [("OrderItems", "ItemStatusId")] = "ix_orderitems_itemstatusid", |
| | 1 | 274 | | [("OrderItems", "OrderCartId")] = "ix_orderitems_ordercartid", |
| | 1 | 275 | | [("OrderSupplierStateHistory", "OrderSupplierStateId")] = "IX_OrderSupplierStateHistory_StateId", |
| | 1 | 276 | | [("OrderSupplierStates", "ProviderKey,ActiveOrderId")] = "UX_OrderSupplierStates_Provider_ActiveOrderId", |
| | 1 | 277 | | [("OrderSupplierStates", "ProviderKey,Stage,LastSyncedAt")] = "IX_OrderSupplierStates_Provider_Stage_LastSyncedA |
| | 1 | 278 | | [("OzonChatOrders", "ClientId")] = "FK_OzonChatOrders_OzonClient", |
| | 1 | 279 | | [("OzonChatOrders", "OrderId")] = "FK_OzonChatOrders_Order", |
| | 1 | 280 | | [("OzonChatResponseStatistics", "OrderId")] = "FK_OzonChatResponseStatistics_Order", |
| | 1 | 281 | | [("OzonPostingCancellations", "EventFingerprint")] = "UX_OzonPostingCancellations_EventFingerprint", |
| | 1 | 282 | | [("OzonPostingCancellations", "OzonClientId,PostingNumber")] = "IX_OzonPostingCancellations_Client_Posting", |
| | 1 | 283 | | [("ProfitLigaCartItems", "ActiveStudioOrderId")] = "UX_ProfitLigaCartItems_ActiveOrder", |
| | 1 | 284 | | [("ProfitLigaCartItems", "CreatedAtUtc")] = "IX_ProfitLigaCartItems_Created", |
| | 1 | 285 | | [("ProfitLigaCartItems", "StudioOrderId,Status")] = "IX_ProfitLigaCartItems_Order_Status", |
| | 1 | 286 | | [("ProfitLigaOrderItems", "ProfitLigaCartItemId")] = "FK_ProfitLigaOrderItems_ProfitLigaCartItems", |
| | 1 | 287 | | [("ProfitLigaOrderItems", "ProfitLigaOrderId")] = "IX_ProfitLigaOrderItems_Order", |
| | 1 | 288 | | [("ProfitLigaOrderItems", "StudioOrderId")] = "FK_ProfitLigaOrderItems_Orders_StudioOrderId", |
| | 1 | 289 | | [("ProfitLigaOrders", "OrderNumber")] = "UX_ProfitLigaOrders_Number", |
| | 1 | 290 | | [("ProfitLigaPointMappings", "ShipmentWarehouseId")] = "UX_ProfitLigaPointMappings_Warehouse", |
| | 1 | 291 | | [("ShateMCartItems", "ActiveStudioOrderId")] = "UX_ShateMCartItems_ActiveStudioOrderId", |
| | 1 | 292 | | [("ShateMCartItems", "StudioOrderId")] = "FK_ShateMCartItems_Orders_StudioOrderId", |
| | 1 | 293 | | [("ShateMOrderItems", "ShateMOrderId,StudioOrderId,PriceId")] = "UX_ShateMOrderItems_Order_StudioOrder_Price", |
| | 1 | 294 | | [("ShateMOrders", "ExternalOrderId")] = "UX_ShateMOrders_ExternalOrderId", |
| | 1 | 295 | | [("StatusTransitionHistory", "EntityType,EntityId")] = "IX_Entity", |
| | 1 | 296 | | [("StatusTransitionHistory", "FromStatusId")] = "IX_FromStatusId", |
| | 1 | 297 | | [("StatusTransitionHistory", "PerformedAt")] = "IX_PerformedAt", |
| | 1 | 298 | | [("StatusTransitionHistory", "StatusTransitionId")] = "IX_StatusTransitionId", |
| | 1 | 299 | | [("StatusTransitionHistory", "ToStatusId")] = "IX_ToStatusId", |
| | 1 | 300 | | [("StatusTransitions", "FromStatusId,ToStatusId,TransactionType")] = "UQ_StatusTransitions_UniqueTransition", |
| | 1 | 301 | | [("SupplierQuotationRequests", "OrderId,RequestedAtUtc")] = "IX_SupplierQuotationRequests_Order_RequestedAtUtc", |
| | 1 | 302 | | [("SupplierQuotationRequests", "ProductId,RequestedAtUtc")] = "IX_SupplierQuotationRequests_Product_RequestedAtU |
| | 1 | 303 | | [("SupplierStatuses", "ProviderKey,StatusKind,ExternalCode")] = "IX_SupplierStatuses_Provider_Kind_ExternalCode" |
| | 1 | 304 | | [("SupplierStatuses", "ProviderKey,StatusKind,Name")] = "UX_SupplierStatuses_Provider_Kind_Name", |
| | 1 | 305 | | [("TransactionTimeTrackingResults", "TrackingKey")] = "UX_TransactionTimeTrackingResults_TrackingKey", |
| | 1 | 306 | | [("TransactionTimeTrackingResults", "TrackingSessionId")] = "FK_TransactionTimeTrackingResults_SessionId", |
| | 1 | 307 | | [("TransactionTimeTrackingSessions", "IsCompleted,IsAbandoned,StartedAtUtc")] = "IX_TransactionTimeTrackingSessi |
| | 1 | 308 | | [("TransactionTimeTrackingSessions", "TrackingKey")] = "UX_TransactionTimeTrackingSessions_TrackingKey", |
| | 1 | 309 | | [("UserDataScopes", "DataScopeId")] = "FK_UserDataScopes_DataScopes_DataScopeId", |
| | 1 | 310 | | [("WarehouseMapping", "OzonClientId")] = "FK_WarehouseMapping_OzonClient", |
| | 1 | 311 | | [("WarehouseStockSnapshot", "RowKey")] = "UX_WarehouseStockSnapshot_RowKey", |
| | 1 | 312 | | [("WarehouseStockSnapshot", "SyncRunId")] = "FK_WarehouseStockSnapshot_SyncRun", |
| | 1 | 313 | | [("orders_history", "OrderId")] = "IX_OrdersHistory_OrderId", |
| | 1 | 314 | | }; |
| | | 315 | | |
| | | 316 | | /// <summary> |
| | | 317 | | /// Имена внешних ключей, которые на проде отличаются от выводимых EF. |
| | | 318 | | /// Ключ — таблица и колонки FK через запятую. Как и с индексами, нужны, чтобы |
| | | 319 | | /// миграции обращались к ограничениям по их фактическим именам в боевой БД. |
| | | 320 | | /// </summary> |
| | 1 | 321 | | internal static readonly Dictionary<(string Table, string Columns), string> ForeignKeyNames = new() |
| | 1 | 322 | | { |
| | 1 | 323 | | [("ApiSupplierWarehouses", "WarehouseId")] = "FK_ApiSupplierWarehouses_Warehouses", |
| | 1 | 324 | | [("AppStatuses", "StatusColorId")] = "FK_AppStatuses_StatusColors", |
| | 1 | 325 | | [("ArmtekOrderItems", "ArmtekCartItemId")] = "FK_ArmtekOrderItems_ArmtekCartItems", |
| | 1 | 326 | | [("ArmtekOrderItems", "ArmtekOrderId")] = "FK_ArmtekOrderItems_ArmtekOrders", |
| | 1 | 327 | | [("BackgroundJobExecutions", "ScheduleId")] = "fk_execution_schedule", |
| | 1 | 328 | | [("BackgroundJobSchedules", "OzonClientId")] = "fk_schedule_ozon_client", |
| | 1 | 329 | | [("BackgroundJobSteps", "ExecutionId")] = "fk_step_execution", |
| | 1 | 330 | | [("BackgroundOrderMatches", "ExecutionId")] = "fk_match_execution", |
| | 1 | 331 | | [("BackgroundOrderMatches", "OrderId")] = "fk_match_order", |
| | 1 | 332 | | [("BackgroundOrderMatches", "ReportLoadId")] = "fk_match_report", |
| | 1 | 333 | | [("BackgroundOrderMatches", "StepId")] = "fk_match_step", |
| | 1 | 334 | | [("BackgroundReportLoads", "ExecutionId")] = "fk_report_execution", |
| | 1 | 335 | | [("BackgroundReportLoads", "OzonClientId")] = "fk_report_ozon_client", |
| | 1 | 336 | | [("BackgroundReportLoads", "StepId")] = "fk_report_step", |
| | 1 | 337 | | [("BackgroundTransactionResults", "ExecutionId")] = "fk_result_execution", |
| | 1 | 338 | | [("BackgroundTransactionResults", "OrderId")] = "fk_result_order", |
| | 1 | 339 | | [("BackgroundTransactionResults", "OrderMatchId")] = "fk_result_match", |
| | 1 | 340 | | [("BackgroundTransactionResults", "StepId")] = "fk_result_step", |
| | 1 | 341 | | [("BackgroundTransactionResults", "TransactionId")] = "fk_result_transaction", |
| | 1 | 342 | | [("BergDeliveryAddressMappings", "ShipmentWarehouseId")] = "FK_BergDeliveryAddressMappings_Warehouses", |
| | 1 | 343 | | [("BergOrderItems", "BergCartItemId")] = "FK_BergOrderItems_BergCartItems", |
| | 1 | 344 | | [("BergOrderItems", "BergOrderId")] = "FK_BergOrderItems_BergOrders", |
| | 1 | 345 | | [("BitrixStockArchiveItems", "ExecutionId")] = "fk_archive_item_execution", |
| | 1 | 346 | | [("BitrixStockAutoScheduleRuns", "ScheduleId")] = "fk_auto_run_schedule", |
| | 1 | 347 | | [("BitrixStockClearItems", "ExecutionId")] = "fk_clear_item_execution", |
| | 1 | 348 | | [("BitrixStockPushItems", "ExecutionId")] = "fk_push_item_execution", |
| | 1 | 349 | | [("BitrixStockUnarchiveItems", "ExecutionId")] = "fk_unarchive_item_execution", |
| | 1 | 350 | | [("ClientStatuses", "StatusColorId")] = "FK_clientstatuses_StatusColors_StatusColorId", |
| | 1 | 351 | | [("DataScopeSetItems", "DataScopeSetId")] = "FK_DataScopeSetItems_DataScopeSets", |
| | 1 | 352 | | [("Deliveries", "ProviderId")] = "Deliveries_ibfk_1", |
| | 1 | 353 | | [("EmailAttachmentInboxes", "EmailMessageInboxId")] = "FK_EmailAttachmentInboxes_EmailMessageInboxes", |
| | 1 | 354 | | [("EmailAttachmentProcessingResults", "EmailAttachmentInboxId")] = "FK_EmailAttachmentProcessingResults_EmailAtt |
| | 1 | 355 | | [("EmailAttachmentProcessingResults", "EmailMessageInboxId")] = "FK_EmailAttachmentProcessingResults_EmailMessag |
| | 1 | 356 | | [("EmailAttachmentProcessingResults", "EmailRoutingRuleId")] = "FK_EmailAttachmentProcessingResults_EmailRouting |
| | 1 | 357 | | [("ExcludedArticles", "OzonClientId")] = "FK_ExcludedArticles_OzonClients", |
| | 1 | 358 | | [("FavoritPartsOrderItems", "FavoritPartsCartItemId")] = "FK_FavoritPartsOrderItems_FavoritPartsCartItems", |
| | 1 | 359 | | [("FavoritPartsOrderItems", "FavoritPartsOrderId")] = "FK_FavoritPartsOrderItems_FavoritPartsOrders", |
| | 1 | 360 | | [("FidStatItems", "SnapshotId")] = "FK_FidStatItems_Snapshot", |
| | 1 | 361 | | [("ForumAutoOrderItems", "ForumAutoCartItemId")] = "FK_ForumAutoOrderItems_ForumAutoCartItems", |
| | 1 | 362 | | [("ForumAutoOrderItems", "ForumAutoOrderId")] = "FK_ForumAutoOrderItems_ForumAutoOrders", |
| | 1 | 363 | | [("ItemStatuses", "StatusColorId")] = "FK_ItemStatuses_StatusColors", |
| | 1 | 364 | | [("MikadoCartItems", "StudioOrderId")] = "FK_MikadoCartItems_Orders", |
| | 1 | 365 | | [("MlAutoCartItems", "StudioOrderId")] = "FK_MlAutoCartItems_Orders", |
| | 1 | 366 | | [("MlAutoDeliveryAddressMappings", "ShipmentWarehouseId")] = "FK_MlAutoDeliveryAddressMappings_Warehouses", |
| | 1 | 367 | | [("MlAutoOrderItems", "MlAutoOrderId")] = "FK_MlAutoOrderItems_Orders", |
| | 1 | 368 | | [("MlAutoRuCartItems", "StudioOrderId")] = "FK_MlAutoRuCartItems_Orders", |
| | 1 | 369 | | [("MlAutoRuDeliveryAddressMappings", "ShipmentWarehouseId")] = "FK_MlAutoRuDeliveryAddressMappings_Warehouses", |
| | 1 | 370 | | [("MlAutoRuOrderItems", "MlAutoRuOrderId")] = "FK_MlAutoRuOrderItems_Orders", |
| | 1 | 371 | | [("MoskvorechieIstraCartItems", "StudioOrderId")] = "FK_MoskvorechieIstraCartItems_StudioOrder", |
| | 1 | 372 | | [("MoskvorechieIstraOrderItems", "MoskvorechieIstraOrderId")] = "FK_MoskvorechieIstraOrderItems_Order", |
| | 1 | 373 | | [("MoskvorechieIstraOrderItems", "StudioOrderId")] = "FK_MoskvorechieIstraOrderItems_StudioOrder", |
| | 1 | 374 | | [("OrderCarts", "CartStatusId")] = "ordercarts_ibfk_1", |
| | 1 | 375 | | [("OrderExtraExpenses", "ExpenseTypeId")] = "FK_OrderExtraExpenses_ExpenseType", |
| | 1 | 376 | | [("OrderExtraExpenses", "OrderId")] = "FK_OrderExtraExpenses_Order", |
| | 1 | 377 | | [("OrderHistoryOneCPostingLinks", "OrderHistoryId")] = "FK_OrderHistoryOneCPostingLinks_History", |
| | 1 | 378 | | [("OrderHistoryOneCPostingLinks", "PostingId")] = "FK_OrderHistoryOneCPostingLinks_Posting", |
| | 1 | 379 | | [("OrderItems", "ItemStatusId")] = "orderitems_ibfk_1", |
| | 1 | 380 | | [("OrderItems", "OrderCartId")] = "orderitems_ibfk_2", |
| | 1 | 381 | | [("OrderOzonPromotionConditions", "SnapshotId")] = "FK_OzonPromoCondition_Snapshot", |
| | 1 | 382 | | [("OrderReturns", "OrderId")] = "FK_OrderReturns_Orders", |
| | 1 | 383 | | [("OrderReturns", "OzonClientId")] = "FK_OrderReturns_OzonClients", |
| | 1 | 384 | | [("OrderSupplierStateHistory", "OrderHistoryId")] = "FK_OrderSupplierStateHistory_OrderHistory_OrderHistoryId", |
| | 1 | 385 | | [("OrderSupplierStateHistory", "OrderSupplierStateId")] = "FK_OrderSupplierStateHistory_States_OrderSupplierStat |
| | 1 | 386 | | [("OzonChatOrders", "ClientId")] = "FK_OzonChatOrders_OzonClient", |
| | 1 | 387 | | [("OzonChatOrders", "OrderId")] = "FK_OzonChatOrders_Order", |
| | 1 | 388 | | [("OzonChatResponseStatistics", "ClientId")] = "FK_OzonChatResponseStatistics_OzonClient", |
| | 1 | 389 | | [("OzonChatResponseStatistics", "OrderId")] = "FK_OzonChatResponseStatistics_Order", |
| | 1 | 390 | | [("OzonPostingCancellationOrders", "CancellationId")] = "FK_OzonPostingCancellationOrders_Cancellations_Cancella |
| | 1 | 391 | | [("ProfitLigaOrderItems", "ProfitLigaCartItemId")] = "FK_ProfitLigaOrderItems_ProfitLigaCartItems", |
| | 1 | 392 | | [("ProfitLigaOrderItems", "ProfitLigaOrderId")] = "FK_ProfitLigaOrderItems_ProfitLigaOrders", |
| | 1 | 393 | | [("ProfitLigaPointMappings", "ShipmentWarehouseId")] = "FK_ProfitLigaPointMappings_Warehouses", |
| | 1 | 394 | | [("ShateMOrderItems", "ShateMOrderId")] = "FK_ShateMOrderItems_Orders", |
| | 1 | 395 | | [("StatusTransitionHistory", "FromStatusId")] = "StatusTransitionHistory_ibfk_2", |
| | 1 | 396 | | [("StatusTransitionHistory", "StatusTransitionId")] = "StatusTransitionHistory_ibfk_1", |
| | 1 | 397 | | [("StatusTransitionHistory", "ToStatusId")] = "StatusTransitionHistory_ibfk_3", |
| | 1 | 398 | | [("StatusTransitions", "FromStatusId")] = "StatusTransitions_ibfk_1", |
| | 1 | 399 | | [("StatusTransitions", "ToStatusId")] = "StatusTransitions_ibfk_2", |
| | 1 | 400 | | [("SupplierQuotationOffers", "RequestId")] = "FK_SupplierQuotationOffers_Requests", |
| | 1 | 401 | | [("SupplierQuotationRequests", "OrderId")] = "FK_SupplierQuotationRequests_Orders", |
| | 1 | 402 | | [("SupplierQuotationRequests", "ProductId")] = "FK_SupplierQuotationRequests_Products", |
| | 1 | 403 | | [("SupplierQuotationRequests", "SupplierId")] = "FK_SupplierQuotationRequests_Suppliers", |
| | 1 | 404 | | [("TransactionTimeTrackingResults", "TrackingSessionId")] = "FK_TransactionTimeTrackingResults_SessionId", |
| | 1 | 405 | | [("WarehouseMapping", "OzonClientId")] = "FK_WarehouseMapping_OzonClient", |
| | 1 | 406 | | [("WarehouseStockSnapshot", "SyncRunId")] = "FK_WarehouseStockSnapshot_SyncRun", |
| | 1 | 407 | | [("order_extensions", "OrderId")] = "FK_OrderExtensions_Orders", |
| | 1 | 408 | | [("orders_history", "OrderId")] = "FK_OrdersHistory_Orders_OrderId", |
| | 1 | 409 | | }; |
| | | 410 | | |
| | | 411 | | /// <summary> |
| | | 412 | | /// Индексы, которые EF выводит уникальными из связи «один к одному», тогда как |
| | | 413 | | /// в боевой БД они неуникальны. |
| | | 414 | | /// |
| | | 415 | | /// OrderPrices.OrderId: связь Order ↔ OrderPrice описана как 1:1, но в проде |
| | | 416 | | /// 16 234 заказа имеют несколько строк цен. Уникальный индекс там создать нельзя, |
| | | 417 | | /// и раньше именно поэтому схему из модели невозможно было развернуть. |
| | | 418 | | /// Связь в C# остаётся 1:1 — уникальность на уровне БД просто не заявляется. |
| | | 419 | | /// </summary> |
| | 1 | 420 | | internal static readonly HashSet<(string Table, string Columns)> NonUniqueIndexes = new() |
| | 1 | 421 | | { |
| | 1 | 422 | | ("OrderPrices", "OrderId"), |
| | 1 | 423 | | ("PriceIndexes", "OrderPriceId"), |
| | 1 | 424 | | }; |
| | | 425 | | |
| | | 426 | | /// <summary>Индексы, заведённые на проде скриптами в обход модели.</summary> |
| | 1 | 427 | | internal static readonly LegacyIndex[] LegacyIndexes = |
| | 1 | 428 | | { |
| | 1 | 429 | | new("AssemblyListAccessKeys", "idx_alak_active", false, "IsActive"), |
| | 1 | 430 | | new("AssemblyListAccessKeys", "idx_alak_key", true, "AccessKey"), |
| | 1 | 431 | | new("AssemblyListRuns", "idx_alr_client", false, "OzonClientId"), |
| | 1 | 432 | | new("AssemblyListRuns", "idx_alr_started", false, "StartedAtUtc"), |
| | 1 | 433 | | new("BackgroundJobExecutions", "idx_job_type_started", false, "JobType", "StartedAt"), |
| | 1 | 434 | | new("BackgroundJobExecutions", "idx_schedule_started", false, "ScheduleId", "StartedAt"), |
| | 1 | 435 | | new("BackgroundJobExecutions", "idx_status_started", false, "Status", "StartedAt"), |
| | 1 | 436 | | new("BackgroundJobSchedules", "idx_job_type_active", false, "JobType", "IsActive"), |
| | 1 | 437 | | new("BackgroundJobSchedules", "idx_next_run", false, "NextRunTime", "IsActive"), |
| | 1 | 438 | | new("BackgroundJobSteps", "idx_execution_step", false, "ExecutionId", "StepNumber"), |
| | 1 | 439 | | new("BackgroundJobSteps", "idx_status", false, "Status"), |
| | 1 | 440 | | new("BackgroundOrderMatches", "idx_eligibility", false, "IsMatchedInDb", "IsEligibleForProcessing"), |
| | 1 | 441 | | new("BackgroundOrderMatches", "idx_order_number_article", false, "OrderNumber", "Article"), |
| | 1 | 442 | | new("BackgroundReportLoads", "idx_report_code", false, "ReportCode"), |
| | 1 | 443 | | new("BackgroundTransactionResults", "idx_status", false, "Status"), |
| | 1 | 444 | | new("BitrixStockArchiveExecutions", "idx_archive_started_at", false, "StartedAt"), |
| | 1 | 445 | | new("BitrixStockArchiveExecutions", "idx_archive_status_started", false, "Status", "StartedAt"), |
| | 1 | 446 | | new("BitrixStockArchiveExecutions", "uk_archive_job_id", true, "JobId"), |
| | 1 | 447 | | new("BitrixStockArchiveItems", "idx_archive_execution_sort", false, "ExecutionId", "SortOrder"), |
| | 1 | 448 | | new("BitrixStockArchiveItems", "idx_archive_execution_status", false, "ExecutionId", "Status"), |
| | 1 | 449 | | new("BitrixStockAutoScheduleRuns", "idx_run_schedule_started", false, "ScheduleId", "StartedAt"), |
| | 1 | 450 | | new("BitrixStockAutoSchedules", "idx_auto_active", false, "IsActive"), |
| | 1 | 451 | | new("BitrixStockAutoSchedules", "idx_auto_next_run", false, "NextRunAt"), |
| | 1 | 452 | | new("BitrixStockClearExecutions", "idx_started_at", false, "StartedAt"), |
| | 1 | 453 | | new("BitrixStockClearExecutions", "idx_status_started", false, "Status", "StartedAt"), |
| | 1 | 454 | | new("BitrixStockClearExecutions", "uk_job_id", true, "JobId"), |
| | 1 | 455 | | new("BitrixStockClearItems", "idx_execution_sort", false, "ExecutionId", "SortOrder"), |
| | 1 | 456 | | new("BitrixStockClearItems", "idx_execution_status", false, "ExecutionId", "Status"), |
| | 1 | 457 | | new("BitrixStockPushExecutions", "idx_push_started_at", false, "StartedAt"), |
| | 1 | 458 | | new("BitrixStockPushExecutions", "idx_push_status_started", false, "Status", "StartedAt"), |
| | 1 | 459 | | new("BitrixStockPushExecutions", "uk_push_job_id", true, "JobId"), |
| | 1 | 460 | | new("BitrixStockPushItems", "idx_push_execution_sort", false, "ExecutionId", "SortOrder"), |
| | 1 | 461 | | new("BitrixStockPushItems", "idx_push_execution_status", false, "ExecutionId", "Status"), |
| | 1 | 462 | | new("BitrixStockSavedFilter", "IX_BitrixStockSavedFilter_CreatedBy", false, "CreatedBy"), |
| | 1 | 463 | | new("BitrixStockSavedFilter", "IX_BitrixStockSavedFilter_Name", false, "Name"), |
| | 1 | 464 | | new("BitrixStockUnarchiveExecutions", "idx_unarchive_started_at", false, "StartedAt"), |
| | 1 | 465 | | new("BitrixStockUnarchiveExecutions", "idx_unarchive_status_started", false, "Status", "StartedAt"), |
| | 1 | 466 | | new("BitrixStockUnarchiveExecutions", "uk_unarchive_job_id", true, "JobId"), |
| | 1 | 467 | | new("BitrixStockUnarchiveItems", "idx_unarchive_execution_sort", false, "ExecutionId", "SortOrder"), |
| | 1 | 468 | | new("BitrixStockUnarchiveItems", "idx_unarchive_execution_status", false, "ExecutionId", "Status"), |
| | 1 | 469 | | new("ClientStatuses", "IX_ClientStatuses_ClientTypeId", false, "ClientTypeId"), |
| | 1 | 470 | | new("ClientStatuses", "IX_ClientStatuses_Name", true, "Name"), |
| | 1 | 471 | | new("DeliveryProviders", "Name", true, "Name"), |
| | 1 | 472 | | new("ExcelMappings", "IX_ExcelMappings_CreatedBy", false, "CreatedBy"), |
| | 1 | 473 | | new("ExcelMappings", "IX_ExcelMappings_CreatedDate", false, "CreatedDate"), |
| | 1 | 474 | | new("ExcelMappings", "IX_ExcelMappings_Name", false, "Name"), |
| | 1 | 475 | | new("FileUploadRecords", "IX_FileUploadRecords_FileName", true, "FileName"), |
| | 1 | 476 | | new("InterpartsSutCurrencies", "IX_InterpartsSutCurrencies_Name", false, "Name"), |
| | 1 | 477 | | new("Manufacturers", "IX_manufacturers_EtProduserId", false, "EtProduserId"), |
| | 1 | 478 | | new("MlAutoCartItems", "IX_MlAutoCartItems_Order_Status", false, "StudioOrderId", "Status"), |
| | 1 | 479 | | new("MlAutoCartItems", "UX_MlAutoCartItems_ActiveOrder", true, "ActiveStudioOrderId"), |
| | 1 | 480 | | new("MlAutoOrders", "UX_MlAutoOrders_Number", true, "OrderNumber"), |
| | 1 | 481 | | new("MlAutoRuCartItems", "IX_MlAutoRuCartItems_Order_Status", false, "StudioOrderId", "Status"), |
| | 1 | 482 | | new("MlAutoRuCartItems", "UX_MlAutoRuCartItems_ActiveOrder", true, "ActiveStudioOrderId"), |
| | 1 | 483 | | new("MlAutoRuOrders", "UX_MlAutoRuOrders_Number", true, "OrderNumber"), |
| | 1 | 484 | | new("MotexOrderItems", "IX_MotexOrderItems_MotexOrderId", false, "MotexOrderId"), |
| | 1 | 485 | | new("OrderArchives", "IX_OrderArchives_ArchivedBy", false, "ArchivedBy"), |
| | 1 | 486 | | new("OrderHistoryOneCPostings", "IX_OrderHistoryOneCPostings_HistoryBatchKey", false, "HistoryBatchKey"), |
| | 1 | 487 | | new("OrderHistoryOneCPostings", "IX_OrderHistoryOneCPostings_OrderId", false, "OrderId"), |
| | 1 | 488 | | new("OrderHistoryOneCPostings", "IX_OrderHistoryOneCPostings_OrderId_PostedAt", false, "OrderId", "PostedAt"), |
| | 1 | 489 | | new("OrderHistoryOneCPostings", "IX_OrderHistoryOneCPostings_TransactionId", false, "TransactionId"), |
| | 1 | 490 | | new("Orders", "IX_Orders_AppStatusId_LastStatusChangeDate", false, "AppStatusId", "LastStatusChangeDate"), |
| | 1 | 491 | | new("Orders", "IX_Orders_CartId", false, "CartItemId"), |
| | 1 | 492 | | new("Orders", "IX_Orders_LastStatusChangeDate", false, "LastStatusChangeDate"), |
| | 1 | 493 | | new("Orders", "IX_Orders_ProcessingDate", false, "ProcessingDate"), |
| | 1 | 494 | | new("Orders", "IX_Orders_ProductKey", false, "ProductKey"), |
| | 1 | 495 | | new("Orders", "IX_Orders_ShipmentNumber", false, "ShipmentNumber"), |
| | 1 | 496 | | new("OzonChatResponseStatistics", "IX_OzonChatResponseStatistics_ChatId", false, "ChatId"), |
| | 1 | 497 | | new("OzonChatResponseStatistics", "IX_OzonChatResponseStatistics_ClientId_Date", false, "ClientId", "ClientMessa |
| | 1 | 498 | | new("OzonChatResponseTimes", "IX_OzonChatResponseTimes_ChatId", false, "ChatId"), |
| | 1 | 499 | | new("OzonChatResponseTimes", "IX_OzonChatResponseTimes_UserName", false, "UserName"), |
| | 1 | 500 | | new("OzonPushNotifications", "IX_OzonPushNotifications_MessageType", false, "MessageType"), |
| | 1 | 501 | | new("OzonPushNotifications", "IX_OzonPushNotifications_PostingNumber", false, "PostingNumber"), |
| | 1 | 502 | | new("OzonPushNotifications", "IX_OzonPushNotifications_ReceivedAt", false, "ReceivedAt"), |
| | 1 | 503 | | new("OzonPushNotifications", "IX_OzonPushNotifications_SellerId", false, "SellerId"), |
| | 1 | 504 | | new("PriceHistories", "IX_PriceHistories_Article", false, "Article"), |
| | 1 | 505 | | new("PriceHistories", "IX_PriceHistories_Article_CreateDateTime", false, "Article", "CreateDateTime"), |
| | 1 | 506 | | new("PriceHistories", "IX_PriceHistories_BitrixId", false, "BitrixId"), |
| | 1 | 507 | | new("PriceHistories", "IX_PriceHistories_CreateDateTime", false, "CreateDateTime"), |
| | 1 | 508 | | new("Shipments", "UX_Shipments_ShipmentNumber", true, "ShipmentNumber"), |
| | 1 | 509 | | new("StatusTransitionHistory", "IX_TransactionType", false, "TransactionType"), |
| | 1 | 510 | | new("StatusTransitions", "IX_StatusTransitions_DisplayOrder", false, "DisplayOrder"), |
| | 1 | 511 | | new("StatusTransitions", "IX_StatusTransitions_FromStatusId", false, "FromStatusId"), |
| | 1 | 512 | | new("StatusTransitions", "IX_StatusTransitions_IsActive", false, "IsActive"), |
| | 1 | 513 | | new("TransactionTimeTrackingResults", "IX_TransactionTimeTrackingResults_AccessProfileId", false, "AccessProfile |
| | 1 | 514 | | new("TransactionTimeTrackingSessions", "IX_TransactionTimeTrackingSessions_AccessProfileId", false, "AccessProfi |
| | 1 | 515 | | new("order_extensions", "IX_OrderExtensions_OrderId", false, "OrderId"), |
| | 1 | 516 | | new("order_extensions", "UX_OrderExtensions_OrderId_Key", true, "OrderId", "Key"), |
| | 1 | 517 | | new("orders_history", "IX_OrdersHistory_ChangedAt", false, "ChangedAt"), |
| | 1 | 518 | | new("orders_history", "IX_orders_history_OperationId", false, "OperationId"), |
| | 1 | 519 | | }; |
| | | 520 | | |
| | | 521 | | /// <summary> |
| | | 522 | | /// Вызывается последней строкой OnModelCreating — после того, как все сущности |
| | | 523 | | /// сконфигурированы и таблицы получили финальные имена. |
| | | 524 | | /// </summary> |
| | | 525 | | public static void Apply(ModelBuilder modelBuilder) |
| | | 526 | | { |
| | 4 | 527 | | var entityTypesByTable = new Dictionary<string, List<IMutableEntityType>>(); |
| | | 528 | | |
| | 1116 | 529 | | foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
| | | 530 | | { |
| | 554 | 531 | | string? table = entityType.GetTableName(); |
| | 554 | 532 | | if (table is null) |
| | | 533 | | { |
| | | 534 | | continue; |
| | | 535 | | } |
| | | 536 | | |
| | 554 | 537 | | if (!entityTypesByTable.TryGetValue(table, out var bucket)) |
| | | 538 | | { |
| | 554 | 539 | | bucket = new List<IMutableEntityType>(); |
| | 554 | 540 | | entityTypesByTable[table] = bucket; |
| | | 541 | | } |
| | | 542 | | |
| | 554 | 543 | | bucket.Add(entityType); |
| | | 544 | | |
| | 13648 | 545 | | foreach (var property in entityType.GetProperties()) |
| | | 546 | | { |
| | 6270 | 547 | | var key = (table, property.GetColumnName()); |
| | | 548 | | |
| | 6270 | 549 | | if (ColumnTypes.TryGetValue(key, out string? columnType)) |
| | | 550 | | { |
| | 420 | 551 | | property.SetColumnType(columnType); |
| | | 552 | | } |
| | | 553 | | |
| | 6270 | 554 | | if (RequiredColumns.Contains(key)) |
| | | 555 | | { |
| | 9 | 556 | | property.IsNullable = false; |
| | | 557 | | } |
| | | 558 | | } |
| | | 559 | | } |
| | | 560 | | |
| | 728 | 561 | | foreach (var legacyIndex in LegacyIndexes) |
| | | 562 | | { |
| | 360 | 563 | | if (!entityTypesByTable.TryGetValue(legacyIndex.Table, out var candidates)) |
| | | 564 | | { |
| | | 565 | | continue; |
| | | 566 | | } |
| | | 567 | | |
| | 816 | 568 | | foreach (var entityType in candidates) |
| | | 569 | | { |
| | 270 | 570 | | var properties = ResolveProperties(entityType, legacyIndex.Columns); |
| | 270 | 571 | | if (properties is null || entityType.FindIndex(properties) is not null) |
| | | 572 | | { |
| | | 573 | | continue; |
| | | 574 | | } |
| | | 575 | | |
| | 264 | 576 | | var index = entityType.AddIndex(properties); |
| | 264 | 577 | | index.IsUnique = legacyIndex.IsUnique; |
| | 264 | 578 | | index.SetDatabaseName(legacyIndex.Name); |
| | 264 | 579 | | break; |
| | | 580 | | } |
| | | 581 | | } |
| | | 582 | | |
| | 1116 | 583 | | foreach (var entityType in modelBuilder.Model.GetEntityTypes()) |
| | | 584 | | { |
| | 554 | 585 | | string? table = entityType.GetTableName(); |
| | 554 | 586 | | if (table is null) |
| | | 587 | | { |
| | | 588 | | continue; |
| | | 589 | | } |
| | | 590 | | |
| | 3444 | 591 | | foreach (var index in entityType.GetDeclaredIndexes()) |
| | | 592 | | { |
| | 2720 | 593 | | string columns = string.Join(',', index.Properties.Select(p => p.GetColumnName())); |
| | | 594 | | |
| | 1168 | 595 | | if (IndexNames.TryGetValue((table, columns), out string? name)) |
| | | 596 | | { |
| | 375 | 597 | | index.SetDatabaseName(name); |
| | | 598 | | } |
| | | 599 | | |
| | 1168 | 600 | | if (NonUniqueIndexes.Contains((table, columns))) |
| | | 601 | | { |
| | 6 | 602 | | index.IsUnique = false; |
| | | 603 | | } |
| | | 604 | | } |
| | | 605 | | |
| | 2136 | 606 | | foreach (var foreignKey in entityType.GetDeclaredForeignKeys()) |
| | | 607 | | { |
| | 1028 | 608 | | string columns = string.Join(',', foreignKey.Properties.Select(p => p.GetColumnName())); |
| | | 609 | | |
| | 514 | 610 | | if (ForeignKeyNames.TryGetValue((table, columns), out string? name)) |
| | | 611 | | { |
| | 259 | 612 | | foreignKey.SetConstraintName(name); |
| | | 613 | | } |
| | | 614 | | } |
| | | 615 | | } |
| | 4 | 616 | | } |
| | | 617 | | |
| | | 618 | | /// <summary> |
| | | 619 | | /// Возвращает свойства сущности по именам колонок или null, если сопоставить удалось не все. |
| | | 620 | | /// </summary> |
| | | 621 | | internal static List<IMutableProperty>? ResolveProperties(IMutableEntityType entityType, IReadOnlyList<string> colum |
| | | 622 | | { |
| | 270 | 623 | | var resolved = new List<IMutableProperty>(columns.Count); |
| | | 624 | | |
| | 1248 | 625 | | foreach (string column in columns) |
| | | 626 | | { |
| | 354 | 627 | | var property = entityType.GetProperties() |
| | 3246 | 628 | | .FirstOrDefault(p => string.Equals(p.GetColumnName(), column, StringComparison.Ordinal)); |
| | | 629 | | |
| | 354 | 630 | | if (property is null) |
| | | 631 | | { |
| | 0 | 632 | | return null; |
| | | 633 | | } |
| | | 634 | | |
| | 354 | 635 | | resolved.Add(property); |
| | | 636 | | } |
| | | 637 | | |
| | 270 | 638 | | return resolved; |
| | 0 | 639 | | } |
| | | 640 | | } |