From 29337e8f424c422e2674df14dc61c61cf176d6a2 Mon Sep 17 00:00:00 2001 From: cawcenter Date: Sun, 14 Dec 2025 12:15:06 -0500 Subject: [PATCH] fix: add missing parent tables and correct field names in schema MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL FIXES: - Added 'sites' table (SUPER PARENT) - referenced by 10+ tables - Added 'campaign_masters' table - referenced by 3 tables - Fixed field names: campaign → campaign_id, site → site_id - Organized schema into dependency batches (Batch 1→2→3) This fixes the root cause of foreign key constraint failures. --- complete_schema.sql | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/complete_schema.sql b/complete_schema.sql index 158e615..59326b0 100644 --- a/complete_schema.sql +++ b/complete_schema.sql @@ -2,12 +2,48 @@ -- Creates all remaining tables with proper relationships -- ============================================ --- CONTENT FACTORY / SEO ENGINE +-- BATCH 1: PARENT TABLES (NO DEPENDENCIES) +-- These MUST be created first as other tables reference them +-- ============================================ + +-- Super Parent #1: Sites - Referenced by 10+ tables +CREATE TABLE IF NOT EXISTS sites ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid (), + name VARCHAR(255) NOT NULL, + url VARCHAR(500), + domain VARCHAR(255), + status VARCHAR(50) DEFAULT 'active', + wp_url VARCHAR(500), + wp_username VARCHAR(255), + wp_app_password TEXT, + site_globals JSONB, + date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + date_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- Super Parent #2: Campaign Masters - Referenced by headline_inventory, content_fragments +CREATE TABLE IF NOT EXISTS campaign_masters ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid (), + site_id UUID REFERENCES sites (id) ON DELETE CASCADE, + name VARCHAR(255) NOT NULL, + headline_spintax_root TEXT, + niche_variables JSONB, + location_mode VARCHAR(100), + location_target VARCHAR(255), + batch_count INTEGER DEFAULT 0, + status VARCHAR(50) DEFAULT 'active', + target_word_count INTEGER DEFAULT 1500, + article_template UUID, + date_created TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +-- ============================================ +-- BATCH 2: CONTENT FACTORY / SEO ENGINE -- ============================================ CREATE TABLE IF NOT EXISTS headline_inventory ( id UUID PRIMARY KEY DEFAULT gen_random_uuid (), - campaign UUID REFERENCES campaign_masters (id) ON DELETE CASCADE, + campaign_id UUID REFERENCES campaign_masters (id) ON DELETE CASCADE, final_title_text VARCHAR(500), status VARCHAR(50) DEFAULT 'available', used_on_article UUID, @@ -26,8 +62,8 @@ CREATE TABLE IF NOT EXISTS content_fragments ( CREATE TABLE IF NOT EXISTS production_queue ( id UUID PRIMARY KEY DEFAULT gen_random_uuid (), - site UUID REFERENCES sites (id) ON DELETE CASCADE, - campaign UUID REFERENCES campaign_masters (id) ON DELETE CASCADE, + site_id UUID REFERENCES sites (id) ON DELETE CASCADE, + campaign_id UUID REFERENCES campaign_masters (id) ON DELETE CASCADE, status VARCHAR(50) DEFAULT 'pending', total_requested INTEGER, completed_count INTEGER DEFAULT 0,