Feat[BE-260]: create BOP migration

This commit is contained in:
aguhh18
2025-11-17 11:03:15 +07:00
parent 60757237c0
commit cb1df12b7e
6 changed files with 137 additions and 0 deletions
@@ -0,0 +1,40 @@
CREATE TABLE expense_realizations (
id BIGSERIAL PRIMARY KEY,
expense_nonstock_id BIGINT,
realization_qty NUMERIC(15, 3) NOT NULL,
realization_unit_price NUMERIC(15, 3) NOT NULL,
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
);
-- Tambahkan Foreign Key ke expense_nonstocks
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'expense_nonstocks') THEN
ALTER TABLE expense_realizations
ADD CONSTRAINT fk_expense_realizations_nonstock_id
FOREIGN KEY (expense_nonstock_id) REFERENCES expense_nonstocks(id);
END IF;
END $$;
-- Tambahkan Foreign Key ke users (created_by)
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM pg_tables WHERE tablename = 'users') THEN
ALTER TABLE expense_realizations
ADD CONSTRAINT fk_expense_realizations_created_by
FOREIGN KEY (created_by) REFERENCES users(id);
END IF;
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);