Add website static image slots with page grouping and bilingual captions.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-16 23:56:16 +03:30
co-authored by Cursor
parent b991a60cbc
commit 1c7678ce67
18 changed files with 1098 additions and 6 deletions
@@ -0,0 +1,83 @@
-- Meshkee CMS — website static image slots (single or list, optional link per image)
CREATE TABLE website_image_slots (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
business_id BIGINT NOT NULL,
slot_key VARCHAR(100) NOT NULL,
kind VARCHAR(20) NOT NULL,
label VARCHAR(255) NOT NULL,
aspect_ratio VARCHAR(20),
recommended_width INTEGER,
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT website_image_slots_business_id_fkey
FOREIGN KEY (business_id) REFERENCES businesses (id) ON DELETE CASCADE,
CONSTRAINT website_image_slots_kind_check
CHECK (kind IN ('single', 'list')),
CONSTRAINT website_image_slots_aspect_ratio_check
CHECK (aspect_ratio IS NULL OR aspect_ratio ~ '^[0-9]{1,3}:[0-9]{1,3}$'),
CONSTRAINT website_image_slots_recommended_width_check
CHECK (recommended_width IS NULL OR recommended_width > 0)
);
CREATE UNIQUE INDEX website_image_slots_business_id_slot_key_unique
ON website_image_slots (business_id, slot_key);
CREATE INDEX idx_website_image_slots_business_id
ON website_image_slots (business_id);
CREATE TRIGGER website_image_slots_set_updated_at
BEFORE UPDATE ON website_image_slots
FOR EACH ROW
EXECUTE FUNCTION set_updated_at();
CREATE TABLE website_image_slot_items (
id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
slot_id BIGINT NOT NULL,
image_media_id BIGINT NOT NULL,
title VARCHAR(255),
link_url VARCHAR(2048),
sort_order INTEGER NOT NULL DEFAULT 0,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
CONSTRAINT website_image_slot_items_slot_id_fkey
FOREIGN KEY (slot_id) REFERENCES website_image_slots (id) ON DELETE CASCADE,
CONSTRAINT website_image_slot_items_image_media_id_fkey
FOREIGN KEY (image_media_id) REFERENCES media (id) ON DELETE RESTRICT
);
CREATE INDEX idx_website_image_slot_items_slot_id
ON website_image_slot_items (slot_id);
CREATE INDEX idx_website_image_slot_items_image_media_id
ON website_image_slot_items (image_media_id);
CREATE TRIGGER website_image_slot_items_set_updated_at
BEFORE UPDATE ON website_image_slot_items
FOR EACH ROW
EXECUTE FUNCTION set_updated_at();
-- First test slot for live sanihome.ir (no-op if that domain is not in this database)
INSERT INTO website_image_slots (
business_id,
slot_key,
kind,
label,
aspect_ratio,
recommended_width,
sort_order
)
SELECT DISTINCT ON (d.business_id)
d.business_id,
'home-hero',
'list',
'Home hero',
'16:9',
1440,
0
FROM domains d
WHERE lower(regexp_replace(d.host, '^www\.', '')) = 'sanihome.ir'
ON CONFLICT (business_id, slot_key) DO NOTHING;
@@ -0,0 +1,19 @@
-- Fixed slot count: NULL = unlimited list; 1 for single; N for a row of N uploaders
ALTER TABLE website_image_slots
ADD COLUMN IF NOT EXISTS item_count INTEGER;
ALTER TABLE website_image_slots
DROP CONSTRAINT IF EXISTS website_image_slots_item_count_check;
ALTER TABLE website_image_slots
ADD CONSTRAINT website_image_slots_item_count_check
CHECK (item_count IS NULL OR item_count >= 1);
UPDATE website_image_slots
SET item_count = 1
WHERE kind = 'single' AND item_count IS NULL;
UPDATE website_image_slots
SET item_count = 2
WHERE slot_key = 'two-banner-row' AND kind = 'list';
@@ -0,0 +1,7 @@
-- Group static image slots by website page (home, products, about, …)
ALTER TABLE website_image_slots
ADD COLUMN IF NOT EXISTS page_key VARCHAR(100) NOT NULL DEFAULT 'home';
CREATE INDEX IF NOT EXISTS idx_website_image_slots_business_id_page_key
ON website_image_slots (business_id, page_key);
@@ -0,0 +1,14 @@
-- Bilingual titles + subtext on each static image item
ALTER TABLE website_image_slot_items
ADD COLUMN IF NOT EXISTS title_fa VARCHAR(255);
ALTER TABLE website_image_slot_items
ADD COLUMN IF NOT EXISTS title_en VARCHAR(255);
ALTER TABLE website_image_slot_items
ADD COLUMN IF NOT EXISTS subtext VARCHAR(500);
UPDATE website_image_slot_items
SET title_fa = title
WHERE title_fa IS NULL AND title IS NOT NULL;