Ship legacy migrate APIs, portfolio/blog old-id schema, and admin migrate/purge flows.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-07-29 16:10:41 +03:30
co-authored by Cursor
parent 7244b70e90
commit 4598add88c
32 changed files with 4234 additions and 265 deletions
@@ -0,0 +1,8 @@
-- Link Meshkee businesses to legacy WillaEngine business ids for selective migration
ALTER TABLE businesses
ADD COLUMN IF NOT EXISTS old_business_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS businesses_old_business_id_unique
ON businesses (old_business_id)
WHERE old_business_id IS NOT NULL;
@@ -0,0 +1,7 @@
-- Link content categories to legacy WillaEngine category ids (per entity type)
ALTER TABLE categories
ADD COLUMN IF NOT EXISTS old_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS categories_business_entity_old_id_unique
ON categories (business_id, entity_type, old_id)
WHERE old_id IS NOT NULL;
@@ -0,0 +1,14 @@
-- Link migrated portfolios / media to legacy WillaEngine ids
ALTER TABLE portfolios
ADD COLUMN IF NOT EXISTS old_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS portfolios_business_old_id_unique
ON portfolios (business_id, old_id)
WHERE old_id IS NOT NULL;
ALTER TABLE media
ADD COLUMN IF NOT EXISTS old_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS media_business_old_id_unique
ON media (business_id, old_id)
WHERE old_id IS NOT NULL;
@@ -0,0 +1,21 @@
-- Bilingual portfolio titles (legacy name / name_en)
ALTER TABLE portfolios
ADD COLUMN IF NOT EXISTS title_fa VARCHAR(255);
ALTER TABLE portfolios
ADD COLUMN IF NOT EXISTS title_en VARCHAR(255);
-- Existing rows: FA from title; EN from content.nameEn when present
UPDATE portfolios
SET title_fa = title
WHERE title_fa IS NULL;
UPDATE portfolios
SET title_en = NULLIF(BTRIM(content->>'nameEn'), '')
WHERE title_en IS NULL
AND content ? 'nameEn';
-- Keep title as the primary FA display title
UPDATE portfolios
SET title = COALESCE(NULLIF(BTRIM(title_fa), ''), title)
WHERE title_fa IS NOT NULL;
+7
View File
@@ -0,0 +1,7 @@
-- Link migrated blogs to legacy WillaEngine article ids
ALTER TABLE blogs
ADD COLUMN IF NOT EXISTS old_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS blogs_business_old_id_unique
ON blogs (business_id, old_id)
WHERE old_id IS NOT NULL;
@@ -0,0 +1,17 @@
-- Customer categories (entity_type) + user legacy ids + blogs old_id unique per post_type
ALTER TYPE media_entity_type ADD VALUE IF NOT EXISTS 'customer';
ALTER TABLE users
ADD COLUMN IF NOT EXISTS old_id BIGINT;
CREATE UNIQUE INDEX IF NOT EXISTS users_old_id_unique
ON users (old_id)
WHERE old_id IS NOT NULL;
-- Articles and news can share numeric ids; scope uniqueness by post_type
DROP INDEX IF EXISTS blogs_business_old_id_unique;
CREATE UNIQUE INDEX IF NOT EXISTS blogs_business_post_type_old_id_unique
ON blogs (business_id, post_type, old_id)
WHERE old_id IS NOT NULL;
@@ -0,0 +1,20 @@
-- Portfolio authors (same pattern as blogs.author_id)
ALTER TABLE portfolios
ADD COLUMN IF NOT EXISTS author_id BIGINT;
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1
FROM pg_constraint
WHERE conname = 'portfolios_author_id_fkey'
) THEN
ALTER TABLE portfolios
ADD CONSTRAINT portfolios_author_id_fkey
FOREIGN KEY (author_id) REFERENCES users (id)
ON UPDATE NO ACTION
ON DELETE SET NULL;
END IF;
END $$;
CREATE INDEX IF NOT EXISTS idx_portfolios_author_id ON portfolios (author_id);