mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
adjust migration for seed and depresiasi
This commit is contained in:
+14
@@ -0,0 +1,14 @@
|
|||||||
|
-- Reverse UPSERT: hapus baris PFK 47 & 48 yang kemungkinan baru diinsert oleh up migration ini.
|
||||||
|
-- Jika sebelumnya sudah ada (ON CONFLICT DO UPDATE), baris ini akan terhapus —
|
||||||
|
-- restore manual dari backup jika diperlukan.
|
||||||
|
DELETE FROM farm_depreciation_manual_inputs
|
||||||
|
WHERE project_flock_id IN (47, 48);
|
||||||
|
|
||||||
|
-- UPDATE rows untuk PFK 4–27 tidak bisa di-reverse secara presisi:
|
||||||
|
-- nilai total_cost sebelum migration ini tidak tersimpan di migration history
|
||||||
|
-- (data awal di-load via cmd/import-farm-depreciation-manual-inputs dari Excel).
|
||||||
|
-- PFK 10 dan 11 tidak berubah (nilai sama dengan state dari migration 20260529144559).
|
||||||
|
-- Jika perlu rollback penuh: restore dari database backup atau re-import Excel lama.
|
||||||
|
|
||||||
|
-- Recompute snapshots setelah rollback
|
||||||
|
TRUNCATE TABLE farm_depreciation_snapshots;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
DROP INDEX IF EXISTS idx_hds_custom_unique;
|
||||||
|
|
||||||
|
-- Remove all per-flock custom curves; they must be re-seeded after rolling back.
|
||||||
|
DELETE FROM house_depreciation_standards WHERE project_flock_ids IS NOT NULL;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX idx_hds_custom_unique
|
||||||
|
ON house_depreciation_standards (house_type, day, effective_date)
|
||||||
|
WHERE project_flock_ids IS NOT NULL;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
-- Allow multiple custom depreciation curves per (house_type, day, effective_date)
|
||||||
|
-- for different flock groups. Previously idx_hds_custom_unique only keyed on
|
||||||
|
-- (house_type, day, effective_date), so separate curves for different project_flock_ids
|
||||||
|
-- arrays on the same date were blocked.
|
||||||
|
|
||||||
|
DROP INDEX IF EXISTS idx_hds_custom_unique;
|
||||||
|
|
||||||
|
CREATE UNIQUE INDEX idx_hds_custom_unique
|
||||||
|
ON house_depreciation_standards (house_type, day, effective_date, project_flock_ids)
|
||||||
|
WHERE project_flock_ids IS NOT NULL;
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[8,13,17]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
multiplication_percentage, depreciation_percent, standard_week, name)
|
multiplication_percentage, depreciation_percent, standard_week, name)
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[18,14,12,15,9,19]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
multiplication_percentage, depreciation_percent, standard_week, name)
|
multiplication_percentage, depreciation_percent, standard_week, name)
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[26]::bigint[]
|
||||||
|
AND house_type = 'close_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
-- house_type: close_house
|
-- house_type: close_house
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[20]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
-- house_type: open_house
|
-- house_type: open_house
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[4]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
-- house_type: open_house
|
-- house_type: open_house
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[5]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
-- house_type: open_house
|
-- house_type: open_house
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
+6
@@ -3,6 +3,12 @@
|
|||||||
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
-- depreciation_percent diturunkan = (1 - multiplication_percentage) * 100.
|
||||||
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
-- Lookup engine: ? = ANY(project_flock_ids) — satu baris dipakai semua flock.
|
||||||
|
|
||||||
|
-- Hapus custom curve untuk array ini agar INSERT idempoten.
|
||||||
|
DELETE FROM house_depreciation_standards
|
||||||
|
WHERE project_flock_ids = ARRAY[6]::bigint[]
|
||||||
|
AND house_type = 'open_house'::house_type_enum
|
||||||
|
AND effective_date = DATE '2026-06-03';
|
||||||
|
|
||||||
-- house_type: open_house
|
-- house_type: open_house
|
||||||
INSERT INTO house_depreciation_standards
|
INSERT INTO house_depreciation_standards
|
||||||
(project_flock_ids, house_type, day, effective_date,
|
(project_flock_ids, house_type, day, effective_date,
|
||||||
Reference in New Issue
Block a user