mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-34): extend DB schema and update master data APIs [partial]
✅ DB Schema: product_warehouse entity and migration ✅ Master Data: added filter params to getall APIs 🚧 Pending: stock_logs implementation and adjustment APIs
This commit is contained in:
@@ -36,3 +36,9 @@ DROP TABLE IF EXISTS projects;
|
||||
DROP INDEX IF EXISTS users_id_user_unique;
|
||||
DROP INDEX IF EXISTS users_email_unique;
|
||||
DROP TABLE IF EXISTS users;
|
||||
DROP INDEX IF EXISTS idx_product_warehouses_unique;
|
||||
DROP INDEX IF EXISTS idx_product_warehouses_deleted_at;
|
||||
DROP INDEX IF EXISTS idx_product_warehouses_warehouse_id;
|
||||
DROP INDEX IF EXISTS idx_product_warehouses_product_id;
|
||||
DROP TABLE IF EXISTS product_warehouses;
|
||||
DROP TABLE IF EXISTS stock_logs;
|
||||
@@ -232,3 +232,45 @@ CREATE TABLE projects (
|
||||
deleted_at TIMESTAMPTZ,
|
||||
created_by BIGINT REFERENCES users(id) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
);
|
||||
|
||||
-- PRODUCT WAREHOUSES TABLE
|
||||
CREATE TABLE product_warehouses (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
product_id BIGINT NOT NULL REFERENCES products(id),
|
||||
warehouse_id BIGINT NOT NULL REFERENCES warehouses(id),
|
||||
quantity INTEGER NOT NULL DEFAULT 0,
|
||||
created_by BIGINT NOT NULL REFERENCES users(id),
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- INDEXES
|
||||
CREATE INDEX idx_product_warehouses_product_id ON product_warehouses(product_id);
|
||||
CREATE INDEX idx_product_warehouses_warehouse_id ON product_warehouses(warehouse_id);
|
||||
CREATE INDEX idx_product_warehouses_deleted_at ON product_warehouses(deleted_at);
|
||||
CREATE UNIQUE INDEX idx_product_warehouses_unique ON product_warehouses(product_id, warehouse_id) WHERE deleted_at IS NULL;
|
||||
|
||||
-- STOCK LOGS
|
||||
CREATE TABLE stock_logs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
trancaction_type VARCHAR(20) NOT NULL,
|
||||
quantity NUMERIC(15,3) NOT NULL,
|
||||
before_quantity NUMERIC(15,3) NOT NULL,
|
||||
after_quantity NUMERIC(15,3) NOT NULL,
|
||||
log_type VARCHAR(50) NOT NULL,
|
||||
log_id BIGINT NOT NULL,
|
||||
note TEXT,
|
||||
product_warehouse_id BIGINT NOT NULL REFERENCES product_warehouses(id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
created_by BIGINT NOT NULL REFERENCES users(id) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
created_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ DEFAULT NOW(),
|
||||
deleted_at TIMESTAMPTZ
|
||||
);
|
||||
|
||||
-- Create indexes for better performance
|
||||
CREATE INDEX stock_logs_product_warehouse_id_idx ON stock_logs (product_warehouse_id);
|
||||
CREATE INDEX stock_logs_log_type_log_id_idx ON stock_logs (log_type, log_id);
|
||||
CREATE INDEX stock_logs_created_by_idx ON stock_logs (created_by);
|
||||
CREATE INDEX stock_logs_created_at_idx ON stock_logs (created_at);
|
||||
CREATE INDEX stock_logs_deleted_at_idx ON stock_logs (deleted_at);
|
||||
@@ -674,6 +674,12 @@ func seedNonstocks(tx *gorm.DB, createdBy uint, uoms map[string]uint, suppliers
|
||||
return nil
|
||||
}
|
||||
|
||||
// nanti saya isi
|
||||
func seedProductWarehouse(tx *gorm.DB, createdBy uint, products map[string]uint, warehouses map[string]uint) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func seedFlags(tx *gorm.DB, flagableID uint, flagableType string, flags []utils.FlagType) error {
|
||||
if len(flags) == 0 {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user