seed stuff
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
-- Migration: add JSONB grass types to lawn_sections, enable seed products, and store seeding type on logs
|
||||
-- 1) Lawn sections: add grass_types JSONB and backfill from grass_type CSV
|
||||
ALTER TABLE lawn_sections
|
||||
ADD COLUMN IF NOT EXISTS grass_types JSONB;
|
||||
|
||||
-- Backfill: split grass_type CSV to JSON array when present
|
||||
UPDATE lawn_sections
|
||||
SET grass_types = (
|
||||
CASE
|
||||
WHEN grass_type IS NULL OR trim(grass_type) = '' THEN NULL
|
||||
ELSE (
|
||||
SELECT jsonb_agg(trim(x)) FROM (
|
||||
SELECT regexp_split_to_table(grass_type, '\s*,\s*') AS x
|
||||
) s WHERE trim(x) <> ''
|
||||
)
|
||||
END
|
||||
)
|
||||
WHERE grass_types IS NULL;
|
||||
|
||||
-- 2) Products: allow 'seed' type and add seed_blend JSONB
|
||||
DO $$
|
||||
DECLARE cname text;
|
||||
BEGIN
|
||||
SELECT conname INTO cname
|
||||
FROM pg_constraint
|
||||
WHERE conrelid = 'products'::regclass AND contype='c' AND conname LIKE '%product_type%';
|
||||
IF cname IS NOT NULL THEN
|
||||
EXECUTE format('ALTER TABLE products DROP CONSTRAINT %I', cname);
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
ALTER TABLE products
|
||||
ADD CONSTRAINT products_product_type_check CHECK (product_type IN ('granular','liquid','seed'));
|
||||
|
||||
ALTER TABLE products
|
||||
ADD COLUMN IF NOT EXISTS seed_blend JSONB;
|
||||
|
||||
-- 3) Application logs: store seeding type
|
||||
ALTER TABLE application_logs
|
||||
ADD COLUMN IF NOT EXISTS seeding_type VARCHAR(20) CHECK (seeding_type IN ('overseed','new_seed'));
|
||||
|
||||
Reference in New Issue
Block a user