From 5a73ad0164139e347e9f3663df1420c19096426c Mon Sep 17 00:00:00 2001 From: aguhh18 Date: Fri, 21 Nov 2025 01:06:48 +0700 Subject: [PATCH] Fix[BE-261]: delete timestampz on expense nonstock anda expense reaalizations table --- ...4529_create_expense_nonstocks_table.up.sql | 9 ++----- ...8_create_expense_realizations_table.up.sql | 9 ++----- internal/entities/expense_nonstock.go | 27 +++++++------------ internal/entities/expense_realization.go | 21 ++++++--------- 4 files changed, 21 insertions(+), 45 deletions(-) diff --git a/internal/database/migrations/20251117034529_create_expense_nonstocks_table.up.sql b/internal/database/migrations/20251117034529_create_expense_nonstocks_table.up.sql index 330c4d7b..83542bb5 100644 --- a/internal/database/migrations/20251117034529_create_expense_nonstocks_table.up.sql +++ b/internal/database/migrations/20251117034529_create_expense_nonstocks_table.up.sql @@ -7,10 +7,7 @@ CREATE TABLE expense_nonstocks ( qty NUMERIC(15, 3) NOT NULL, unit_price NUMERIC(15, 3) NOT NULL, total_price NUMERIC(15, 3) NOT NULL, - note TEXT NULL, - created_at TIMESTAMPTZ DEFAULT now(), - updated_at TIMESTAMPTZ DEFAULT now(), - deleted_at TIMESTAMPTZ + note TEXT NULL ); -- Tambahkan Foreign Key ke expenses @@ -56,6 +53,4 @@ END $$; -- Index CREATE INDEX idx_expense_nonstocks_expense_id ON expense_nonstocks (expense_id); -CREATE INDEX idx_expense_nonstocks_nonstock_id ON expense_nonstocks (nonstock_id); - -CREATE INDEX idx_expense_nonstocks_deleted_at ON expense_nonstocks (deleted_at); \ No newline at end of file +CREATE INDEX idx_expense_nonstocks_nonstock_id ON expense_nonstocks (nonstock_id); \ No newline at end of file diff --git a/internal/database/migrations/20251117034538_create_expense_realizations_table.up.sql b/internal/database/migrations/20251117034538_create_expense_realizations_table.up.sql index 0886cd7a..ae58ca48 100644 --- a/internal/database/migrations/20251117034538_create_expense_realizations_table.up.sql +++ b/internal/database/migrations/20251117034538_create_expense_realizations_table.up.sql @@ -6,10 +6,7 @@ CREATE TABLE expense_realizations ( realization_total_price NUMERIC(15, 3) NOT NULL, realization_date DATE NOT NULL, note TEXT, - created_by BIGINT, - created_at TIMESTAMPTZ DEFAULT now(), - updated_at TIMESTAMPTZ DEFAULT now(), - deleted_at TIMESTAMPTZ + created_by BIGINT ); -- Tambahkan Foreign Key ke expense_nonstocks @@ -35,6 +32,4 @@ END $$; -- Index CREATE INDEX idx_expense_realizations_nonstock_id ON expense_realizations (expense_nonstock_id); -CREATE INDEX idx_expense_realizations_date ON expense_realizations (realization_date); - -CREATE INDEX idx_expense_realizations_deleted_at ON expense_realizations (deleted_at); \ No newline at end of file +CREATE INDEX idx_expense_realizations_date ON expense_realizations (realization_date); \ No newline at end of file diff --git a/internal/entities/expense_nonstock.go b/internal/entities/expense_nonstock.go index d483e4bf..7be2053a 100644 --- a/internal/entities/expense_nonstock.go +++ b/internal/entities/expense_nonstock.go @@ -1,24 +1,15 @@ package entities -import ( - "time" - - "gorm.io/gorm" -) - type ExpenseNonstock struct { - Id uint64 `gorm:"primaryKey;autoIncrement"` - ExpenseId *uint64 `gorm:""` - ProjectFlockKandangId *uint64 `gorm:""` - KandangId *uint64 `gorm:""` - NonstockId *uint64 `gorm:""` - Qty float64 `gorm:"type:numeric(15,3);not null"` - UnitPrice float64 `gorm:"type:numeric(15,3);not null"` - TotalPrice float64 `gorm:"type:numeric(15,3);not null"` - Note string `gorm:"type:text"` - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + Id uint64 `gorm:"primaryKey;autoIncrement"` + ExpenseId *uint64 `gorm:""` + ProjectFlockKandangId *uint64 `gorm:""` + KandangId *uint64 `gorm:""` + NonstockId *uint64 `gorm:""` + Qty float64 `gorm:"type:numeric(15,3);not null"` + UnitPrice float64 `gorm:"type:numeric(15,3);not null"` + TotalPrice float64 `gorm:"type:numeric(15,3);not null"` + Note string `gorm:"type:text"` // Relations Expense *Expense `gorm:"foreignKey:ExpenseId;references:Id"` diff --git a/internal/entities/expense_realization.go b/internal/entities/expense_realization.go index 45a87602..629fdfb7 100644 --- a/internal/entities/expense_realization.go +++ b/internal/entities/expense_realization.go @@ -2,22 +2,17 @@ package entities import ( "time" - - "gorm.io/gorm" ) type ExpenseRealization struct { - Id uint64 `gorm:"primaryKey;autoIncrement"` - ExpenseNonstockId *uint64 `gorm:""` - RealizationQty float64 `gorm:"type:numeric(15,3);not null"` - RealizationUnitPrice float64 `gorm:"type:numeric(15,3);not null"` - RealizationTotalPrice float64 `gorm:"type:numeric(15,3);not null"` - RealizationDate time.Time `gorm:"type:date;not null"` - Note *string `gorm:"type:text"` - CreatedBy *uint64 `gorm:""` - CreatedAt time.Time `gorm:"autoCreateTime"` - UpdatedAt time.Time `gorm:"autoUpdateTime"` - DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` + Id uint64 `gorm:"primaryKey;autoIncrement"` + ExpenseNonstockId *uint64 `gorm:""` + RealizationQty float64 `gorm:"type:numeric(15,3);not null"` + RealizationUnitPrice float64 `gorm:"type:numeric(15,3);not null"` + RealizationTotalPrice float64 `gorm:"type:numeric(15,3);not null"` + RealizationDate time.Time `gorm:"type:date;not null"` + Note *string `gorm:"type:text"` + CreatedBy *uint64 `gorm:""` // Relations ExpenseNonstock *ExpenseNonstock `gorm:"foreignKey:ExpenseNonstockId;references:Id"`