38 lines
1.2 KiB
SQL
38 lines
1.2 KiB
SQL
-- Drop old pick_lists tables
|
|
DROP TABLE IF EXISTS pick_list_items CASCADE;
|
|
DROP TABLE IF EXISTS pick_lists CASCADE;
|
|
|
|
-- Planning history: one row per accepted production plan
|
|
CREATE TABLE IF NOT EXISTS planning_history (
|
|
id SERIAL PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
status VARCHAR(50) DEFAULT 'accepted',
|
|
products_json JSONB,
|
|
summary_json JSONB,
|
|
created_at TIMESTAMP DEFAULT NOW()
|
|
);
|
|
|
|
-- Planning history items: every BOM component for that plan
|
|
CREATE TABLE IF NOT EXISTS planning_history_items (
|
|
id SERIAL PRIMARY KEY,
|
|
planning_id INTEGER NOT NULL REFERENCES planning_history(id) ON DELETE CASCADE,
|
|
component_id INTEGER REFERENCES components(id),
|
|
part_number VARCHAR(100),
|
|
component_name VARCHAR(255),
|
|
category_name VARCHAR(255),
|
|
package_type VARCHAR(100),
|
|
shelf_location VARCHAR(100),
|
|
quantity_needed NUMERIC DEFAULT 0,
|
|
stock_at_time NUMERIC DEFAULT 0,
|
|
shortage NUMERIC DEFAULT 0,
|
|
unit_price NUMERIC DEFAULT 0,
|
|
is_internal BOOLEAN DEFAULT false,
|
|
manufacturer VARCHAR(255),
|
|
supplier VARCHAR(255),
|
|
supplier_part_number VARCHAR(255),
|
|
sources_json JSONB,
|
|
created_at TIMESTAMP DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX IF NOT EXISTS idx_planning_history_items_planning ON planning_history_items(planning_id);
|