mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-18 21:44:08 +01:00
feat: create inventory_status table and modify inventory_items to use status_id
This commit is contained in:
parent
4e42794aad
commit
7d8fd6e10f
@ -12,7 +12,7 @@ CREATE TABLE soil_conditions (
|
||||
CREATE TABLE harvest_units (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
);
|
||||
|
||||
CREATE TABLE plants (
|
||||
uuid UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
|
||||
5
backend/migrations/00005_create_inventory_status.sql
Normal file
5
backend/migrations/00005_create_inventory_status.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE inventory_status (
|
||||
id SERIAL PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE
|
||||
);
|
||||
15
backend/migrations/00006_modify_inventory_table.sql
Normal file
15
backend/migrations/00006_modify_inventory_table.sql
Normal 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);
|
||||
|
||||
7
backend/migrations/00007_create_inventory_status.sql
Normal file
7
backend/migrations/00007_create_inventory_status.sql
Normal 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');
|
||||
Loading…
Reference in New Issue
Block a user