23 lines
1.0 KiB
MySQL
23 lines
1.0 KiB
MySQL
|
|
-- Ingredients table
|
||
|
|
CREATE TABLE ingredients (
|
||
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||
|
|
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||
|
|
outlet_id UUID REFERENCES outlets(id) ON DELETE CASCADE,
|
||
|
|
name VARCHAR(255) NOT NULL,
|
||
|
|
unit_id UUID NOT NULL REFERENCES units(id) ON DELETE CASCADE,
|
||
|
|
cost DECIMAL(12,2) DEFAULT 0,
|
||
|
|
stock DECIMAL(12,3) DEFAULT 0,
|
||
|
|
is_semi_finished BOOLEAN DEFAULT false,
|
||
|
|
is_active BOOLEAN DEFAULT true,
|
||
|
|
metadata JSONB DEFAULT '{}',
|
||
|
|
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||
|
|
updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||
|
|
);
|
||
|
|
|
||
|
|
-- Indexes
|
||
|
|
CREATE INDEX idx_ingredients_organization_id ON ingredients(organization_id);
|
||
|
|
CREATE INDEX idx_ingredients_outlet_id ON ingredients(outlet_id);
|
||
|
|
CREATE INDEX idx_ingredients_unit_id ON ingredients(unit_id);
|
||
|
|
CREATE INDEX idx_ingredients_is_semi_finished ON ingredients(is_semi_finished);
|
||
|
|
CREATE INDEX idx_ingredients_is_active ON ingredients(is_active);
|
||
|
|
CREATE INDEX idx_ingredients_created_at ON ingredients(created_at);
|