feat: create inventory_status table and modify inventory_items to use status_id

This commit is contained in:
Pattadon 2025-04-01 11:06:50 +07:00
parent 4e42794aad
commit 7d8fd6e10f
4 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,5 @@
-- +goose Up
CREATE TABLE inventory_status (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE
);

View File

@ -0,0 +1,15 @@
-- +goose Up
ALTER TABLE inventory_items
ADD COLUMN status_id INT;
UPDATE inventory_items
SET status_id = (SELECT id FROM inventory_status WHERE name = inventory_items.status);
ALTER TABLE inventory_items
DROP COLUMN status;
ALTER TABLE inventory_items
ADD CONSTRAINT fk_inventory_items_status FOREIGN KEY (status_id) REFERENCES inventory_status(id) ON DELETE CASCADE;
CREATE INDEX idx_inventory_items_status_id ON inventory_items(status_id);

View File

@ -0,0 +1,7 @@
-- +goose Up
-- Insert default statuses into the inventory_status table
INSERT INTO inventory_status (name)
VALUES
('In Stock'),
('Low Stock'),
('Out Of Stock');