This commit is contained in:
2026-02-23 16:40:06 +03:00
commit a51d12bc89
169 changed files with 7973 additions and 0 deletions

26
db/30_products.sql Normal file
View File

@@ -0,0 +1,26 @@
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_type WHERE typname = 'product_unit') THEN
CREATE TYPE product_unit AS ENUM ('pcs', 'kg', 'm', 'm2', 'm3', 'bag', 'pack');
END IF;
END;
$$;
CREATE TABLE IF NOT EXISTS products (
id UUID PRIMARY KEY,
sku TEXT NOT NULL UNIQUE,
name TEXT NOT NULL,
description TEXT NOT NULL DEFAULT '',
category_id UUID NOT NULL REFERENCES categories(id),
brand_id UUID NULL REFERENCES brands(id),
unit product_unit NOT NULL,
is_active BOOLEAN NOT NULL DEFAULT TRUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);
DROP TRIGGER IF EXISTS trg_products_updated_at ON products;
CREATE TRIGGER trg_products_updated_at
BEFORE UPDATE ON products
FOR EACH ROW
EXECUTE FUNCTION set_updated_at();