chore(db): Add migration files 051-055 for enhanced audits
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
c9c7c192cd
commit
387bd2f616
26
database/migrations/051_social_media_enhanced.sql
Normal file
26
database/migrations/051_social_media_enhanced.sql
Normal file
@ -0,0 +1,26 @@
|
||||
-- Migration 051: Enhanced Social Media Audit
|
||||
-- Adds profile completeness, activity metrics, and historical tracking
|
||||
-- Date: 2026-02-06
|
||||
|
||||
-- Profile completeness indicators
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_profile_photo BOOLEAN;
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_cover_photo BOOLEAN;
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS has_bio BOOLEAN;
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS profile_description TEXT;
|
||||
|
||||
-- Activity metrics
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posts_count_30d INTEGER;
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posts_count_365d INTEGER;
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS last_post_date TIMESTAMP;
|
||||
|
||||
-- Scoring & analytics
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS posting_frequency_score INTEGER; -- 0-10
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS engagement_rate NUMERIC(5,2); -- percent
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS content_types JSONB; -- {"photos": 12, "videos": 3, "text": 5}
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS profile_completeness_score INTEGER; -- 0-100
|
||||
|
||||
-- Historical tracking
|
||||
ALTER TABLE company_social_media ADD COLUMN IF NOT EXISTS followers_history JSONB; -- [{"date": "2026-02-01", "count": 150}, ...]
|
||||
|
||||
-- Permissions
|
||||
GRANT ALL ON TABLE company_social_media TO nordabiz_app;
|
||||
61
database/migrations/052_gbp_audit_enhanced.sql
Normal file
61
database/migrations/052_gbp_audit_enhanced.sql
Normal file
@ -0,0 +1,61 @@
|
||||
-- Migration 052: Enhanced GBP Audit with Reviews and Extended Attributes
|
||||
-- Date: 2026-02-06
|
||||
|
||||
-- Review management
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS reviews_with_response INTEGER DEFAULT 0;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS reviews_without_response INTEGER DEFAULT 0;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS review_response_rate NUMERIC(5,2);
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS avg_review_response_days NUMERIC(5,1);
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS review_sentiment JSONB; -- {"positive": 15, "neutral": 3, "negative": 2}
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS reviews_30d INTEGER DEFAULT 0;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS review_keywords JSONB; -- ["profesjonalny", "szybko", "polecam"]
|
||||
|
||||
-- Content & activity
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS has_posts BOOLEAN;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS posts_count_30d INTEGER;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS has_products BOOLEAN;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS has_qa BOOLEAN;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS qa_count INTEGER;
|
||||
|
||||
-- Enhanced attributes
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS attributes JSONB; -- {"payment": [...], "accessibility": [...], ...}
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS special_hours JSONB;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS has_special_hours BOOLEAN;
|
||||
|
||||
-- NAP consistency
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS nap_consistent BOOLEAN;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS nap_issues JSONB; -- [{"field": "phone", "gbp": "...", "website": "..."}]
|
||||
|
||||
-- Keywords
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS description_keywords JSONB;
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS keyword_density_score INTEGER; -- 0-100
|
||||
|
||||
-- Photo analysis
|
||||
ALTER TABLE gbp_audits ADD COLUMN IF NOT EXISTS photo_categories JSONB; -- {"interior": 3, "exterior": 2, "team": 1, ...}
|
||||
|
||||
-- NEW TABLE: Individual reviews tracking
|
||||
CREATE TABLE IF NOT EXISTS gbp_reviews (
|
||||
id SERIAL PRIMARY KEY,
|
||||
company_id INTEGER REFERENCES companies(id) ON DELETE CASCADE,
|
||||
google_review_id VARCHAR(255),
|
||||
author_name VARCHAR(255),
|
||||
rating INTEGER NOT NULL CHECK (rating >= 1 AND rating <= 5),
|
||||
text TEXT,
|
||||
publish_time TIMESTAMP,
|
||||
has_owner_response BOOLEAN DEFAULT FALSE,
|
||||
owner_response_text TEXT,
|
||||
owner_response_time TIMESTAMP,
|
||||
sentiment VARCHAR(20), -- positive, neutral, negative
|
||||
keywords JSONB,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
UNIQUE(company_id, google_review_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_gbp_reviews_company ON gbp_reviews(company_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_gbp_reviews_publish ON gbp_reviews(publish_time);
|
||||
CREATE INDEX IF NOT EXISTS idx_gbp_reviews_sentiment ON gbp_reviews(sentiment);
|
||||
|
||||
-- Permissions
|
||||
GRANT ALL ON TABLE gbp_audits TO nordabiz_app;
|
||||
GRANT ALL ON TABLE gbp_reviews TO nordabiz_app;
|
||||
GRANT USAGE, SELECT ON SEQUENCE gbp_reviews_id_seq TO nordabiz_app;
|
||||
45
database/migrations/053_seo_audit_enhanced.sql
Normal file
45
database/migrations/053_seo_audit_enhanced.sql
Normal file
@ -0,0 +1,45 @@
|
||||
-- Migration 053: Enhanced SEO Audit with Local SEO and Citations
|
||||
-- Date: 2026-02-06
|
||||
|
||||
-- Local SEO
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS local_seo_score INTEGER; -- 0-100
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS has_local_business_schema BOOLEAN;
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS local_business_schema_fields JSONB; -- {"name": true, "address": true, ...}
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS nap_on_website JSONB; -- {"name": "...", "address": "...", "phone": "..."}
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS has_google_maps_embed BOOLEAN;
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS has_local_keywords BOOLEAN;
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS local_keywords_found JSONB; -- ["hydraulik wejherowo", ...]
|
||||
|
||||
-- Citations
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS citations_found JSONB; -- [{"directory": "panoramafirm.pl", "url": "...", "status": "found"}]
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS citations_count INTEGER DEFAULT 0;
|
||||
|
||||
-- Content freshness
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS content_freshness_score INTEGER; -- 0-100
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS last_content_update TIMESTAMP;
|
||||
|
||||
-- Score history
|
||||
ALTER TABLE company_website_analysis ADD COLUMN IF NOT EXISTS score_history JSONB; -- [{"date": "2026-02-01", "score": 72}, ...]
|
||||
|
||||
-- NEW TABLE: Company citations in local directories
|
||||
CREATE TABLE IF NOT EXISTS company_citations (
|
||||
id SERIAL PRIMARY KEY,
|
||||
company_id INTEGER REFERENCES companies(id) ON DELETE CASCADE,
|
||||
directory_name VARCHAR(100) NOT NULL,
|
||||
directory_url VARCHAR(500),
|
||||
listing_url VARCHAR(500),
|
||||
status VARCHAR(20) DEFAULT 'unknown', -- found, not_found, incorrect
|
||||
nap_accurate BOOLEAN,
|
||||
details JSONB, -- extra info from the listing
|
||||
checked_at TIMESTAMP DEFAULT NOW(),
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
UNIQUE(company_id, directory_name)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_company_citations_company ON company_citations(company_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_company_citations_status ON company_citations(status);
|
||||
|
||||
-- Permissions
|
||||
GRANT ALL ON TABLE company_website_analysis TO nordabiz_app;
|
||||
GRANT ALL ON TABLE company_citations TO nordabiz_app;
|
||||
GRANT USAGE, SELECT ON SEQUENCE company_citations_id_seq TO nordabiz_app;
|
||||
47
database/migrations/054_competitor_monitoring.sql
Normal file
47
database/migrations/054_competitor_monitoring.sql
Normal file
@ -0,0 +1,47 @@
|
||||
-- Migration 054: Competitor Monitoring
|
||||
-- Tracks competitors and periodic snapshots for change detection
|
||||
-- Date: 2026-02-06
|
||||
|
||||
CREATE TABLE IF NOT EXISTS company_competitors (
|
||||
id SERIAL PRIMARY KEY,
|
||||
company_id INTEGER REFERENCES companies(id) ON DELETE CASCADE,
|
||||
competitor_place_id VARCHAR(255) NOT NULL,
|
||||
competitor_name VARCHAR(255),
|
||||
competitor_address VARCHAR(500),
|
||||
competitor_rating NUMERIC(2,1),
|
||||
competitor_review_count INTEGER,
|
||||
competitor_category VARCHAR(255),
|
||||
competitor_website VARCHAR(500),
|
||||
added_by VARCHAR(20) DEFAULT 'auto', -- auto, manual
|
||||
is_active BOOLEAN DEFAULT TRUE,
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
updated_at TIMESTAMP DEFAULT NOW(),
|
||||
UNIQUE(company_id, competitor_place_id)
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS competitor_snapshots (
|
||||
id SERIAL PRIMARY KEY,
|
||||
competitor_id INTEGER REFERENCES company_competitors(id) ON DELETE CASCADE,
|
||||
snapshot_date DATE NOT NULL,
|
||||
rating NUMERIC(2,1),
|
||||
review_count INTEGER,
|
||||
photo_count INTEGER,
|
||||
posts_count INTEGER,
|
||||
has_website BOOLEAN,
|
||||
has_description BOOLEAN,
|
||||
data JSONB, -- full snapshot data
|
||||
changes JSONB, -- delta vs previous snapshot
|
||||
created_at TIMESTAMP DEFAULT NOW(),
|
||||
UNIQUE(competitor_id, snapshot_date)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_competitors_company ON company_competitors(company_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_competitors_active ON company_competitors(is_active);
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_competitor ON competitor_snapshots(competitor_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_snapshots_date ON competitor_snapshots(snapshot_date);
|
||||
|
||||
-- Permissions
|
||||
GRANT ALL ON TABLE company_competitors TO nordabiz_app;
|
||||
GRANT ALL ON TABLE competitor_snapshots TO nordabiz_app;
|
||||
GRANT USAGE, SELECT ON SEQUENCE company_competitors_id_seq TO nordabiz_app;
|
||||
GRANT USAGE, SELECT ON SEQUENCE competitor_snapshots_id_seq TO nordabiz_app;
|
||||
39
database/migrations/055_unified_reports.sql
Normal file
39
database/migrations/055_unified_reports.sql
Normal file
@ -0,0 +1,39 @@
|
||||
-- Migration 055: Unified Audit Reports
|
||||
-- Combines Social Media, GBP, and SEO audits into single reports
|
||||
-- Date: 2026-02-06
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_reports (
|
||||
id SERIAL PRIMARY KEY,
|
||||
company_id INTEGER REFERENCES companies(id) ON DELETE CASCADE,
|
||||
report_type VARCHAR(20) DEFAULT 'full', -- full, social, gbp, seo
|
||||
period_start DATE,
|
||||
period_end DATE,
|
||||
|
||||
-- Overall scores
|
||||
overall_score INTEGER, -- 0-100 composite
|
||||
social_score INTEGER, -- 0-100
|
||||
gbp_score INTEGER, -- 0-100
|
||||
seo_score INTEGER, -- 0-100
|
||||
|
||||
-- Report sections
|
||||
sections JSONB, -- {"social": true, "gbp": true, "seo": true, "competitors": true}
|
||||
|
||||
-- Pre-rendered report data
|
||||
data JSONB, -- Full report payload
|
||||
|
||||
-- Metadata
|
||||
custom_message TEXT,
|
||||
generated_by VARCHAR(50) DEFAULT 'system', -- system, admin, api
|
||||
generated_at TIMESTAMP DEFAULT NOW(),
|
||||
status VARCHAR(20) DEFAULT 'draft', -- draft, published
|
||||
|
||||
created_at TIMESTAMP DEFAULT NOW()
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_reports_company ON audit_reports(company_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_reports_status ON audit_reports(status);
|
||||
CREATE INDEX IF NOT EXISTS idx_audit_reports_date ON audit_reports(generated_at);
|
||||
|
||||
-- Permissions
|
||||
GRANT ALL ON TABLE audit_reports TO nordabiz_app;
|
||||
GRANT USAGE, SELECT ON SEQUENCE audit_reports_id_seq TO nordabiz_app;
|
||||
Loading…
Reference in New Issue
Block a user