-- Add campaign dynamic landing pages https://github.com/Photowall/Issuetracker/issues/428

DROP TABLE IF EXISTS campaign_page_content;
DROP TABLE IF EXISTS campaign_pages;


CREATE TABLE IF NOT EXISTS campaign_pages (
	id serial PRIMARY KEY,
	inserted timestamp with time zone DEFAULT now() NOT NULL,
	published timestamp with time zone,
	deleted timestamp with time zone,
	name text NOT NULL,
  description text NOT NULL
);

COMMENT ON COLUMN campaign_pages.name IS 'Used as title in admin only';


CREATE TABLE IF NOT EXISTS campaign_page_content (
	id serial PRIMARY KEY,
	campaign_page_id integer NOT NULL REFERENCES campaign_pages(id),
	inserted timestamp with time zone DEFAULT now() NOT NULL,
	updated timestamp with time zone,
	title text,
	body text,
	meta_title text,
	meta_description text,
	slug text,
	market_locale_id integer NOT NULL REFERENCES market_locales(id),
	noindex boolean DEFAULT false
);


CREATE INDEX ON campaign_page_content(campaign_page_id);
CREATE INDEX ON campaign_page_content(market_locale_id);


CREATE TRIGGER updated_timestamp BEFORE UPDATE ON public.campaign_pages FOR EACH ROW EXECUTE PROCEDURE public.updated_timestamp();
CREATE TRIGGER updated_timestamp BEFORE UPDATE ON public.campaign_page_content FOR EACH ROW EXECUTE PROCEDURE public.updated_timestamp();
