mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 05:21:57 +00:00
add adjust migration
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
# Farm Depreciation Manual Inputs Import
|
||||
|
||||
Command ini dipakai untuk bulk import data ke tabel `farm_depreciation_manual_inputs` dari file Excel (`.xlsx`).
|
||||
|
||||
## Command
|
||||
|
||||
```bash
|
||||
go run ./cmd/import-farm-depreciation-manual-inputs --file <path.xlsx> [--sheet <name>] [--apply]
|
||||
```
|
||||
|
||||
## Flags
|
||||
|
||||
- `--file` (required): path file `.xlsx`.
|
||||
- `--sheet` (optional): nama sheet. Jika tidak diisi, command pakai sheet pertama.
|
||||
- `--apply` (optional): default `false` (dry-run). Jika `true`, command menulis ke database.
|
||||
|
||||
## Mode
|
||||
|
||||
- Dry-run (default):
|
||||
- parsing dan validasi semua baris.
|
||||
- validasi `project_flock_id` terhadap farm aktif kategori `LAYING`.
|
||||
- menampilkan `PLAN` + daftar error.
|
||||
- tidak menulis data.
|
||||
|
||||
- Apply (`--apply`):
|
||||
- semua validasi tetap dijalankan dulu.
|
||||
- jika ada 1 error, proses dihentikan.
|
||||
- jika valid, upsert dijalankan dalam 1 transaksi (fail-fast).
|
||||
- setelah upsert, snapshot di `farm_depreciation_snapshots` dihapus mulai `cutover_date` untuk `project_flock_id` terkait.
|
||||
|
||||
## Format Excel
|
||||
|
||||
Template tersedia di:
|
||||
|
||||
- `docs/templates/farm_depreciation_manual_inputs.xlsx`
|
||||
|
||||
Header wajib ada di baris 1 (case-insensitive, trim-spaces):
|
||||
|
||||
- `project_flock_id` (required, integer > 0)
|
||||
- `total_cost` (required, numeric >= 0)
|
||||
- `cutover_date` (required, format `YYYY-MM-DD`)
|
||||
- `note` (optional, max 1000 karakter)
|
||||
|
||||
Catatan:
|
||||
|
||||
- Dalam 1 file tidak boleh ada duplikat `project_flock_id`.
|
||||
- `project_flock_id` harus mengarah ke `project_flocks` yang `deleted_at IS NULL` dan `category = LAYING`.
|
||||
|
||||
## Contoh
|
||||
|
||||
Dry-run:
|
||||
|
||||
```bash
|
||||
env DB_HOST=127.0.0.1 DB_PORT=5432 DB_NAME=lti DB_USER=postgres DB_PASSWORD=postgres \
|
||||
go run ./cmd/import-farm-depreciation-manual-inputs \
|
||||
--file docs/templates/farm_depreciation_manual_inputs.xlsx
|
||||
```
|
||||
|
||||
Apply:
|
||||
|
||||
```bash
|
||||
env DB_HOST=127.0.0.1 DB_PORT=5432 DB_NAME=lti DB_USER=postgres DB_PASSWORD=postgres \
|
||||
go run ./cmd/import-farm-depreciation-manual-inputs \
|
||||
--file /path/to/farm_depreciation_manual_inputs.xlsx \
|
||||
--sheet manual_inputs \
|
||||
--apply
|
||||
```
|
||||
|
||||
## Error Umum
|
||||
|
||||
- `required header is missing`: header wajib tidak ditemukan.
|
||||
- `must be a positive integer`: `project_flock_id` bukan integer valid.
|
||||
- `must be greater than or equal to 0`: `total_cost` negatif.
|
||||
- `must follow format YYYY-MM-DD`: `cutover_date` tidak sesuai format.
|
||||
- `duplicate value ...`: `project_flock_id` duplikat dalam file yang sama.
|
||||
- `must reference an active LAYING project_flock`: farm tidak valid untuk import ini.
|
||||
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user