diff --git a/src/main/java/org/openlmis/stockmanagement/domain/card/StockCard.java b/src/main/java/org/openlmis/stockmanagement/domain/card/StockCard.java index ab7eab29..dcf41c3f 100644 --- a/src/main/java/org/openlmis/stockmanagement/domain/card/StockCard.java +++ b/src/main/java/org/openlmis/stockmanagement/domain/card/StockCard.java @@ -94,7 +94,7 @@ public class StockCard extends BaseEntity implements IdentifiableByOrderableLotU @Column private UUID lotId; - @Column + @Column(nullable = false) private UUID unitOfOrderableId; @LazyCollection(FALSE) diff --git a/src/main/java/org/openlmis/stockmanagement/domain/event/StockEventLineItem.java b/src/main/java/org/openlmis/stockmanagement/domain/event/StockEventLineItem.java index 5e139731..2da6b367 100644 --- a/src/main/java/org/openlmis/stockmanagement/domain/event/StockEventLineItem.java +++ b/src/main/java/org/openlmis/stockmanagement/domain/event/StockEventLineItem.java @@ -84,6 +84,7 @@ public class StockEventLineItem extends BaseEntity @JoinColumn(name = "stockEventLineItemId") private List stockAdjustments; + @Column(nullable = false) private UUID unitOfOrderableId; /** diff --git a/src/main/java/org/openlmis/stockmanagement/domain/physicalinventory/PhysicalInventoryLineItem.java b/src/main/java/org/openlmis/stockmanagement/domain/physicalinventory/PhysicalInventoryLineItem.java index d7ea5c75..b1879704 100644 --- a/src/main/java/org/openlmis/stockmanagement/domain/physicalinventory/PhysicalInventoryLineItem.java +++ b/src/main/java/org/openlmis/stockmanagement/domain/physicalinventory/PhysicalInventoryLineItem.java @@ -48,9 +48,11 @@ public class PhysicalInventoryLineItem implements VvmApplicable, IdentifiableByOrderableLotUnit { @Column(nullable = false) private UUID orderableId; + @Column private UUID lotId; - @Column + + @Column(nullable = false) private UUID unitOfOrderableId; //when saving draft quantity is allowed to be null diff --git a/src/main/resources/db/migration/20240801140000000__remove_indices_with_nullable_unitOfOrderableId.sql b/src/main/resources/db/migration/20240801140000000__remove_indices_with_nullable_unitOfOrderableId.sql new file mode 100644 index 00000000..63427916 --- /dev/null +++ b/src/main/resources/db/migration/20240801140000000__remove_indices_with_nullable_unitOfOrderableId.sql @@ -0,0 +1,12 @@ +-- Cleanup indexes +DROP INDEX IF EXISTS uniq_stock_card_facility_program_product_lot_unit; +DROP INDEX IF EXISTS uniq_stock_card_facility_program_product_lot; +DROP INDEX IF EXISTS uniq_stock_card_facility_program_product_unit; +DROP INDEX IF EXISTS uniq_stock_card_facility_program_product; + +-- Create new indexes assuming unitOfOrderableId never null +CREATE UNIQUE INDEX uniq_stock_card_facility_program_product_lot_unit + ON stock_cards (facilityId, programId, orderableId, lotId, unitOfOrderableId) WHERE lotId IS NOT NULL; + +CREATE UNIQUE INDEX uniq_stock_card_facility_program_product_unit + ON stock_cards (facilityId, programId, orderableId, unitOfOrderableId) WHERE lotId IS NULL;