All checks were successful
Deploy production / deploy (push) Successful in 1m12s
194 lines
5.1 KiB
SQL
194 lines
5.1 KiB
SQL
CREATE TABLE "stats"."eb_item" (
|
|
"wave" text,
|
|
"fieldwork_end" date,
|
|
"topic" text,
|
|
"qcode" text NOT NULL,
|
|
"item" text,
|
|
"country" text,
|
|
"share" double precision,
|
|
CONSTRAINT "eb_item_pkey" PRIMARY KEY("wave","topic","item","country")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."elec_election" (
|
|
"election_id" text PRIMARY KEY,
|
|
"country" char(3) NOT NULL,
|
|
"kind" text NOT NULL,
|
|
"date" date NOT NULL,
|
|
"name" text NOT NULL,
|
|
"source_id" text NOT NULL,
|
|
"total_seats" integer
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."elec_result" (
|
|
"election_id" text,
|
|
"level" text,
|
|
"area_code" text,
|
|
"area_name" text,
|
|
"party" text,
|
|
"votes" bigint,
|
|
"seats" integer,
|
|
CONSTRAINT "elec_result_pkey" PRIMARY KEY("election_id","level","area_code","party")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."elec_turnout" (
|
|
"election_id" text,
|
|
"level" text,
|
|
"area_code" text,
|
|
"area_name" text,
|
|
"electorate" bigint,
|
|
"ballots" bigint,
|
|
"valid" bigint,
|
|
"blank" bigint,
|
|
"invalid" bigint,
|
|
CONSTRAINT "elec_turnout_pkey" PRIMARY KEY("election_id","level","area_code")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."gdelt_theme_vol" (
|
|
"date" date,
|
|
"country" char(3),
|
|
"theme" text,
|
|
"vol_pct" double precision,
|
|
CONSTRAINT "gdelt_theme_vol_pkey" PRIMARY KEY("date","country","theme")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."gt_trending" (
|
|
"geo" text,
|
|
"date" date,
|
|
"rank" integer NOT NULL,
|
|
"query" text,
|
|
"approx_traffic" integer,
|
|
"pub_date" timestamp with time zone,
|
|
"news" text,
|
|
CONSTRAINT "gt_trending_pkey" PRIMARY KEY("geo","date","query")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."op_poll" (
|
|
"series" text,
|
|
"poll_key" text,
|
|
"fieldwork_end" date NOT NULL,
|
|
"pollster" text NOT NULL,
|
|
"sample" integer,
|
|
"option" text,
|
|
"value" double precision,
|
|
"seen_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "op_poll_pkey" PRIMARY KEY("series","poll_key","option")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."op_wiki_snapshot" (
|
|
"page" text,
|
|
"revid" bigint,
|
|
"fetched_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"wikitext" text NOT NULL,
|
|
CONSTRAINT "op_wiki_snapshot_pkey" PRIMARY KEY("page","revid")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."whr_score" (
|
|
"year" integer,
|
|
"country" text,
|
|
"iso3" char(3),
|
|
"rank" integer,
|
|
"ladder" double precision,
|
|
"lower" double precision,
|
|
"upper" double precision,
|
|
"gdp" double precision,
|
|
"social" double precision,
|
|
"health" double precision,
|
|
"freedom" double precision,
|
|
"generosity" double precision,
|
|
"corruption" double precision,
|
|
"dystopia" double precision,
|
|
CONSTRAINT "whr_score_pkey" PRIMARY KEY("year","country")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_compass_override" (
|
|
"party_id" text PRIMARY KEY,
|
|
"x" double precision NOT NULL,
|
|
"y" double precision NOT NULL,
|
|
"note" text
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_country" (
|
|
"iso3" char(3) PRIMARY KEY,
|
|
"id" text NOT NULL UNIQUE,
|
|
"iso_num" text NOT NULL,
|
|
"name" text NOT NULL,
|
|
"region" text NOT NULL,
|
|
"liberal_meaning" text,
|
|
"main_divide" text,
|
|
"note" text,
|
|
"profile" jsonb,
|
|
"sort" integer NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_cultural_map" (
|
|
"iso3" char(3),
|
|
"wave" text,
|
|
"year_from" integer,
|
|
"year_to" integer,
|
|
"trad_secular" double precision,
|
|
"surv_selfexp" double precision,
|
|
"n" integer,
|
|
"source" text,
|
|
CONSTRAINT "wo_cultural_map_pkey" PRIMARY KEY("iso3","wave")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_narrative" (
|
|
"sort" integer PRIMARY KEY,
|
|
"event" text NOT NULL,
|
|
"years" text NOT NULL,
|
|
"views" jsonb NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_party" (
|
|
"party_id" text PRIMARY KEY,
|
|
"iso3" char(3),
|
|
"name" text,
|
|
"abbrev" text,
|
|
"family" text,
|
|
"ches_id" integer,
|
|
"manifesto_id" integer,
|
|
"vparty_id" integer,
|
|
"partyfacts_id" integer,
|
|
"sort" integer
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_party_position" (
|
|
"party_id" text,
|
|
"year" integer,
|
|
"source" text,
|
|
"dim" text,
|
|
"value" double precision,
|
|
"vote_share" double precision,
|
|
CONSTRAINT "wo_party_position_pkey" PRIMARY KEY("party_id","year","source","dim")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_source" (
|
|
"sort" integer PRIMARY KEY,
|
|
"name" text NOT NULL,
|
|
"href" text NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stats"."wo_value_score" (
|
|
"iso3" char(3),
|
|
"wave" text,
|
|
"item_code" text,
|
|
"item_label" text,
|
|
"stat" text,
|
|
"value" double precision,
|
|
"n" integer,
|
|
CONSTRAINT "wo_value_score_pkey" PRIMARY KEY("iso3","wave","item_code","stat")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE INDEX "elec_result_area_idx" ON "stats"."elec_result" ("level","area_code");--> statement-breakpoint
|
|
CREATE INDEX "op_poll_series_date_idx" ON "stats"."op_poll" ("series","fieldwork_end");--> statement-breakpoint
|
|
CREATE INDEX "wo_party_iso3_idx" ON "stats"."wo_party" ("iso3");--> statement-breakpoint
|
|
DO $$
|
|
BEGIN
|
|
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_app') THEN
|
|
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA stats TO personal_app;
|
|
END IF;
|
|
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'personal_ro') THEN
|
|
GRANT SELECT ON ALL TABLES IN SCHEMA stats TO personal_ro;
|
|
END IF;
|
|
END $$;
|