From a06ee6f3952b3ff3deb6b00e5b488110487f454d Mon Sep 17 00:00:00 2001 From: Capybara-z Date: Thu, 3 Apr 2025 02:04:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=81=D1=82=D0=BE=D0=BB=D0=B1=D1=86=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Добавил создание столбца в купонах days --- assets/schema.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/assets/schema.sql b/assets/schema.sql index b3de6a4b..9db6f6ae 100644 --- a/assets/schema.sql +++ b/assets/schema.sql @@ -72,11 +72,22 @@ CREATE TABLE IF NOT EXISTS coupons id SERIAL PRIMARY KEY, code TEXT UNIQUE NOT NULL, amount INTEGER NOT NULL, + days INTEGER CHECK (days > 0 OR days IS NULL), usage_limit INTEGER NOT NULL DEFAULT 1, usage_count INTEGER NOT NULL DEFAULT 0, is_used BOOLEAN NOT NULL DEFAULT FALSE ); +DO $$ +BEGIN + IF NOT EXISTS ( + SELECT 1 FROM information_schema.columns + WHERE table_name = 'coupons' AND column_name = 'days' + ) THEN + ALTER TABLE coupons ADD COLUMN days INTEGER CHECK (days > 0 OR days IS NULL); + END IF; +END$$; + CREATE TABLE IF NOT EXISTS coupon_usages ( coupon_id INTEGER NOT NULL REFERENCES coupons (id) ON DELETE CASCADE,