mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
Merge branch 'fix/daily-checklist-fk' into 'development'
Fix/daily checklist fk See merge request mbugroup/lti-api!596
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE daily_checklist_empty_kandangs
|
||||
DROP CONSTRAINT IF EXISTS fk_dcek_kandang;
|
||||
|
||||
ALTER TABLE daily_checklist_empty_kandangs
|
||||
ADD CONSTRAINT fk_dcek_kandang
|
||||
FOREIGN KEY (kandang_id) REFERENCES kandangs (id) ON DELETE CASCADE;
|
||||
|
||||
COMMIT;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
BEGIN;
|
||||
|
||||
ALTER TABLE daily_checklist_empty_kandangs
|
||||
DROP CONSTRAINT IF EXISTS fk_dcek_kandang;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM daily_checklist_empty_kandangs dcek
|
||||
LEFT JOIN kandang_groups kg ON kg.id = dcek.kandang_id
|
||||
WHERE kg.id IS NULL
|
||||
AND dcek.deleted_at IS NULL
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Cannot fix FK: some kandang_id values do not exist in kandang_groups';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE daily_checklist_empty_kandangs
|
||||
ADD CONSTRAINT fk_dcek_kandang
|
||||
FOREIGN KEY (kandang_id) REFERENCES kandang_groups (id) ON DELETE CASCADE;
|
||||
|
||||
COMMIT;
|
||||
@@ -2127,7 +2127,7 @@ func (s chickinService) UpdateChickInDate(ctx *fiber.Ctx, req *validation.Update
|
||||
return fiber.NewError(fiber.StatusNotFound, "Project flock kandang tidak ditemukan")
|
||||
}
|
||||
|
||||
return s.Repository.DB().WithContext(ctx.Context()).Transaction(func(tx *gorm.DB) error {
|
||||
if err := s.Repository.DB().WithContext(ctx.Context()).Transaction(func(tx *gorm.DB) error {
|
||||
if err := s.Repository.UpdateChickInDateByProjectFlockKandangID(ctx.Context(), tx, req.ProjectFlockKandangId, newDate); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -2139,5 +2139,10 @@ func (s chickinService) UpdateChickInDate(ctx *fiber.Ctx, req *validation.Update
|
||||
WHERE project_flock_kandangs_id = ?
|
||||
AND deleted_at IS NULL
|
||||
`, req.ChickInDate, req.ProjectFlockKandangId).Error
|
||||
})
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
s.invalidateDepreciationSnapshots(ctx.Context(), nil, []uint{req.ProjectFlockKandangId}, newDate)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user