init
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
-- Drop inventory movements table
|
||||
DROP TABLE IF EXISTS inventory_movements;
|
||||
@@ -0,0 +1,39 @@
|
||||
-- Inventory movements table
|
||||
CREATE TABLE inventory_movements (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
outlet_id UUID NOT NULL REFERENCES outlets(id) ON DELETE CASCADE,
|
||||
product_id UUID NOT NULL REFERENCES products(id) ON DELETE CASCADE,
|
||||
movement_type VARCHAR(50) NOT NULL CHECK (movement_type IN ('sale', 'purchase', 'adjustment', 'return', 'refund', 'void', 'transfer_in', 'transfer_out', 'damage', 'expiry')),
|
||||
quantity INTEGER NOT NULL,
|
||||
previous_quantity INTEGER NOT NULL,
|
||||
new_quantity INTEGER NOT NULL,
|
||||
unit_cost DECIMAL(10,2) DEFAULT 0.00,
|
||||
total_cost DECIMAL(10,2) DEFAULT 0.00,
|
||||
reference_type VARCHAR(50) CHECK (reference_type IN ('order', 'payment', 'refund', 'void', 'manual', 'transfer', 'purchase_order')),
|
||||
reference_id UUID,
|
||||
order_id UUID REFERENCES orders(id) ON DELETE SET NULL,
|
||||
payment_id UUID REFERENCES payments(id) ON DELETE SET NULL,
|
||||
user_id UUID NOT NULL REFERENCES users(id) ON DELETE RESTRICT,
|
||||
reason VARCHAR(255),
|
||||
notes TEXT,
|
||||
metadata JSONB DEFAULT '{}',
|
||||
created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW()
|
||||
);
|
||||
|
||||
-- Indexes
|
||||
CREATE INDEX idx_inventory_movements_organization_id ON inventory_movements(organization_id);
|
||||
CREATE INDEX idx_inventory_movements_outlet_id ON inventory_movements(outlet_id);
|
||||
CREATE INDEX idx_inventory_movements_product_id ON inventory_movements(product_id);
|
||||
CREATE INDEX idx_inventory_movements_movement_type ON inventory_movements(movement_type);
|
||||
CREATE INDEX idx_inventory_movements_reference_type ON inventory_movements(reference_type);
|
||||
CREATE INDEX idx_inventory_movements_reference_id ON inventory_movements(reference_id);
|
||||
CREATE INDEX idx_inventory_movements_order_id ON inventory_movements(order_id);
|
||||
CREATE INDEX idx_inventory_movements_payment_id ON inventory_movements(payment_id);
|
||||
CREATE INDEX idx_inventory_movements_user_id ON inventory_movements(user_id);
|
||||
CREATE INDEX idx_inventory_movements_created_at ON inventory_movements(created_at);
|
||||
|
||||
-- Composite indexes for common queries
|
||||
CREATE INDEX idx_inventory_movements_outlet_product ON inventory_movements(outlet_id, product_id);
|
||||
CREATE INDEX idx_inventory_movements_type_date ON inventory_movements(movement_type, created_at);
|
||||
CREATE INDEX idx_inventory_movements_reference ON inventory_movements(reference_type, reference_id);
|
||||
@@ -0,0 +1,5 @@
|
||||
-- Remove image and printer_type fields from products table
|
||||
DROP INDEX IF EXISTS idx_products_printer_type;
|
||||
ALTER TABLE products
|
||||
DROP COLUMN IF EXISTS image_url,
|
||||
DROP COLUMN IF EXISTS printer_type;
|
||||
@@ -0,0 +1,7 @@
|
||||
-- Add image and printer_type fields to products table
|
||||
ALTER TABLE products
|
||||
ADD COLUMN image_url VARCHAR(500),
|
||||
ADD COLUMN printer_type VARCHAR(50) DEFAULT 'kitchen';
|
||||
|
||||
-- Index for printer_type
|
||||
CREATE INDEX idx_products_printer_type ON products(printer_type);
|
||||
@@ -0,0 +1,2 @@
|
||||
-- Drop tables table
|
||||
DROP TABLE IF EXISTS tables;
|
||||
@@ -0,0 +1,30 @@
|
||||
-- Tables table
|
||||
CREATE TABLE tables (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE,
|
||||
outlet_id UUID NOT NULL REFERENCES outlets(id) ON DELETE CASCADE,
|
||||
table_name VARCHAR(100) NOT NULL,
|
||||
start_time TIMESTAMP WITH TIME ZONE,
|
||||
status VARCHAR(50) DEFAULT 'available' CHECK (status IN ('available', 'occupied', 'reserved', 'cleaning', 'maintenance')),
|
||||
order_id UUID REFERENCES orders(id) ON DELETE SET NULL,
|
||||
payment_amount DECIMAL(10,2) DEFAULT 0.00 CHECK (payment_amount >= 0),
|
||||
position_x DECIMAL(10,2) DEFAULT 0.00,
|
||||
position_y DECIMAL(10,2) DEFAULT 0.00,
|
||||
capacity INTEGER DEFAULT 4 CHECK (capacity >= 1 AND capacity <= 20),
|
||||
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_tables_organization_id ON tables(organization_id);
|
||||
CREATE INDEX idx_tables_outlet_id ON tables(outlet_id);
|
||||
CREATE INDEX idx_tables_order_id ON tables(order_id);
|
||||
CREATE INDEX idx_tables_status ON tables(status);
|
||||
CREATE INDEX idx_tables_is_active ON tables(is_active);
|
||||
CREATE INDEX idx_tables_table_name ON tables(table_name);
|
||||
CREATE INDEX idx_tables_created_at ON tables(created_at);
|
||||
|
||||
-- Unique constraint for table name within an outlet
|
||||
CREATE UNIQUE INDEX idx_tables_outlet_table_name ON tables(outlet_id, table_name) WHERE is_active = true;
|
||||
Reference in New Issue
Block a user