--
-- PostgreSQL database dump
--

-- Dumped from database version 10.15 (Ubuntu 10.15-0ubuntu0.18.04.1)
-- Dumped by pg_dump version 10.13 (Ubuntu 10.13-1.pgdg18.04+1)

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: v1; Type: SCHEMA; Schema: -; Owner:  
--

CREATE SCHEMA v1;


--ALTER SCHEMA v1 OWNER TO  ;

--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: 
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: 
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: bootstrap_schema_version(text, text); Type: FUNCTION; Schema: public; Owner:  
--

CREATE FUNCTION public.bootstrap_schema_version(_schema_name text, _first text) RETURNS integer
    LANGUAGE plpgsql
    AS $$DECLARE
 _result INTEGER DEFAULT 1;
BEGIN
  INSERT INTO public.version_info(
            schema_name, touched, min_app_version, max_app_version, schema_version)
    VALUES (_schema_name, now(), '0', '0', _first);
 RETURN _result;
END;$$;


--ALTER FUNCTION public.bootstrap_schema_version(_schema_name text, _first text) OWNER TO  ;

--
-- Name: check_schema_version(text, text); Type: FUNCTION; Schema: public; Owner:  
--

CREATE FUNCTION public.check_schema_version(_schema_name text, _expected text) RETURNS integer
    LANGUAGE plpgsql
    AS $$DECLARE
 _version_info public.version_info;
 _result INTEGER DEFAULT 1;
BEGIN
 SELECT * INTO STRICT _version_info FROM public.version_info WHERE schema_name = _schema_name AND schema_version = _expected;
 RETURN _result;
END;$$;


--ALTER FUNCTION public.check_schema_version(_schema_name text, _expected text) OWNER TO  ;

--
-- Name: update_schema_version(text, text, text); Type: FUNCTION; Schema: public; Owner:  
--

CREATE FUNCTION public.update_schema_version(_schema_name text, _from text, _to text) RETURNS text
    LANGUAGE plpgsql
    AS $$DECLARE
	_version_info public.version_info;
BEGIN
	SELECT * INTO STRICT _version_info FROM public.version_info WHERE schema_name = _schema_name AND schema_version = _from;

	UPDATE public.version_info SET schema_version = _to WHERE schema_name = _schema_name;

	RETURN _to;
END;$$;


--ALTER FUNCTION public.update_schema_version(_schema_name text, _from text, _to text) OWNER TO  ;

--
-- Name: delete_old_data(text); Type: FUNCTION; Schema: v1; Owner:  
--

CREATE FUNCTION v1.delete_old_data(apikey text) RETURNS void
    LANGUAGE plpgsql
    AS $$

begin
delete from v1.doc_parsed where user_id = (select id from v1.user where api_key = apiKey) and completed < (now() - INTERVAL '1 month');					  
end;

$$;


--ALTER FUNCTION v1.delete_old_data(apikey text) OWNER TO  ;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: version_info; Type: TABLE; Schema: public; Owner:  
--

CREATE TABLE public.version_info (
    schema_name text NOT NULL,
    touched timestamp without time zone NOT NULL,
    min_app_version text NOT NULL,
    max_app_version text NOT NULL,
    schema_version text NOT NULL
);




--
-- Name: dict; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.dict (
    id bigint NOT NULL,
    user_id bigint NOT NULL,
    name text,
    data text
);



--
-- Name: doc_data; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.doc_data (
    id bigint NOT NULL,
    user_id bigint NOT NULL,
    name text,
    data bytea
);



--
-- Name: doc_dict; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.doc_dict (
    doc_id bigint NOT NULL,
    dict_id bigint NOT NULL,
    user_id bigint NOT NULL,
    started timestamp without time zone NOT NULL,
    eta timestamp without time zone NOT NULL,
    completed timestamp without time zone,
    result text
);



--
-- Name: doc_parsed; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.doc_parsed (
    id bigint NOT NULL,
    user_id bigint NOT NULL,
    name text,
    parsed text,
    started timestamp without time zone,
    completed timestamp without time zone,
    eta timestamp without time zone,
    paragraphs jsonb,
    stats jsonb,
    error_code text,
    error_message text,
    scan_settings jsonb,
    whitelist_results jsonb,
    language_detected text DEFAULT 'EN'::text,
    dictionary_results jsonb
);



--
-- Name: global_seq; Type: SEQUENCE; Schema: v1; Owner:  
--

CREATE SEQUENCE v1.global_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: job_queue; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.job_queue (
    itemid bigint NOT NULL,
    job character varying DEFAULT ''::character varying NOT NULL,
    queue_name character varying NOT NULL
);



--
-- Name: page; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.page (
    id bigint NOT NULL,
    web_url_id bigint,
    url text,
    title text,
    paragraphs jsonb,
    stats jsonb,
    error_code text,
    error_message text,
    whitelist_results jsonb,
    language_detected text DEFAULT 'EN'::text
);



--
-- Name: request; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.request (
    id bigint NOT NULL,
    request text,
    started timestamp without time zone,
    completed timestamp without time zone,
    user_id bigint NOT NULL
);



--
-- Name: request_id_seq; Type: SEQUENCE; Schema: v1; Owner:  
--

CREATE SEQUENCE v1.request_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;



--
-- Name: request_id_seq; Type: SEQUENCE OWNED BY; Schema: v1; Owner:  
--

ALTER SEQUENCE v1.request_id_seq OWNED BY v1.request.id;


--
-- Name: scan_job; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.scan_job (
    id bigint NOT NULL,
    user_id bigint NOT NULL,
    started timestamp without time zone NOT NULL,
    eta timestamp without time zone NOT NULL,
    completed timestamp without time zone,
    json_result jsonb,
    json_request jsonb NOT NULL,
    scan_settings jsonb,
    error_code text,
    error_message text,
    whitelist_results jsonb
);


--
-- Name: sqs; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1.sqs (
    message_id text NOT NULL
);



--
-- Name: user; Type: TABLE; Schema: v1; Owner:  
--

CREATE TABLE v1."user" (
    id bigint NOT NULL,
    name text NOT NULL,
    api_key text NOT NULL,
    roles jsonb NOT NULL
);



--
-- Name: user_id_seq; Type: SEQUENCE; Schema: v1; Owner:  
--

CREATE SEQUENCE v1.user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;



--
-- Name: user_id_seq; Type: SEQUENCE OWNED BY; Schema: v1; Owner:  
--

ALTER SEQUENCE v1.user_id_seq OWNED BY v1."user".id;


--
-- Name: request id; Type: DEFAULT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.request ALTER COLUMN id SET DEFAULT nextval('v1.request_id_seq'::regclass);


--
-- Name: user id; Type: DEFAULT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1."user" ALTER COLUMN id SET DEFAULT nextval('v1.user_id_seq'::regclass);


--
-- Data for Name: version_info; Type: TABLE DATA; Schema: public; Owner:  
--

COPY public.version_info (schema_name, touched, min_app_version, max_app_version, schema_version) FROM stdin;
v1	2015-07-03 15:20:09.263761	0	0	0018
\.


--
-- Data for Name: dict; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.dict (id, user_id, name, data) FROM stdin;
\.


--
-- Data for Name: doc_data; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.doc_data (id, user_id, name, data) FROM stdin;
\.


--
-- Data for Name: doc_dict; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.doc_dict (doc_id, dict_id, user_id, started, eta, completed, result) FROM stdin;
\.


--
-- Data for Name: doc_parsed; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.doc_parsed (id, user_id, name, parsed, started, completed, eta, paragraphs, stats, error_code, error_message, scan_settings, whitelist_results, language_detected, dictionary_results) FROM stdin;
\.


--
-- Data for Name: job_queue; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.job_queue (itemid, job, queue_name) FROM stdin;
\.


--
-- Data for Name: page; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.page (id, web_url_id, url, title, paragraphs, stats, error_code, error_message, whitelist_results, language_detected) FROM stdin;
\.


--
-- Data for Name: request; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.request (id, request, started, completed, user_id) FROM stdin;
\.


--
-- Data for Name: scan_job; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.scan_job (id, user_id, started, eta, completed, json_result, json_request, scan_settings, error_code, error_message, whitelist_results) FROM stdin;
\.


--
-- Data for Name: sqs; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1.sqs (message_id) FROM stdin;
\.


--
-- Data for Name: user; Type: TABLE DATA; Schema: v1; Owner:  
--

COPY v1."user" (id, name, api_key, roles) FROM stdin;
1	test	123	[{"name": "basic", "attributes": {"throttlePerMin": "20"}}]
2	Readability App	VTR820618	[{"name": "basic", "attributes": {"throttlePerMin": "20000"}}]
\.


--
-- Name: global_seq; Type: SEQUENCE SET; Schema: v1; Owner:  
--

SELECT pg_catalog.setval('v1.global_seq', 1, false);


--
-- Name: request_id_seq; Type: SEQUENCE SET; Schema: v1; Owner:  
--

SELECT pg_catalog.setval('v1.request_id_seq', 1, false);


--
-- Name: user_id_seq; Type: SEQUENCE SET; Schema: v1; Owner:  
--

SELECT pg_catalog.setval('v1.user_id_seq', 2, true);


--
-- Name: version_info schema_name_pkey; Type: CONSTRAINT; Schema: public; Owner:  
--

ALTER TABLE ONLY public.version_info
    ADD CONSTRAINT schema_name_pkey PRIMARY KEY (schema_name);


--
-- Name: dict dict_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.dict
    ADD CONSTRAINT dict_pkey PRIMARY KEY (id);


--
-- Name: doc_data doc_data_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.doc_data
    ADD CONSTRAINT doc_data_pkey PRIMARY KEY (id);


--
-- Name: doc_dict doc_dict_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.doc_dict
    ADD CONSTRAINT doc_dict_pkey PRIMARY KEY (doc_id, dict_id);


--
-- Name: doc_parsed doc_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.doc_parsed
    ADD CONSTRAINT doc_pkey PRIMARY KEY (id);


--
-- Name: job_queue doc_queue_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.job_queue
    ADD CONSTRAINT doc_queue_pkey PRIMARY KEY (itemid);


--
-- Name: page page_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.page
    ADD CONSTRAINT page_pkey PRIMARY KEY (id);


--
-- Name: request request_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.request
    ADD CONSTRAINT request_pkey PRIMARY KEY (id);


--
-- Name: scan_job scan_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.scan_job
    ADD CONSTRAINT scan_pkey PRIMARY KEY (id);


--
-- Name: sqs sqs_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1.sqs
    ADD CONSTRAINT sqs_pkey PRIMARY KEY (message_id);


--
-- Name: user user_api_key_key; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1."user"
    ADD CONSTRAINT user_api_key_key UNIQUE (api_key);


--
-- Name: user user_name_key; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1."user"
    ADD CONSTRAINT user_name_key UNIQUE (name);


--
-- Name: user user_pkey; Type: CONSTRAINT; Schema: v1; Owner:  
--

ALTER TABLE ONLY v1."user"
    ADD CONSTRAINT user_pkey PRIMARY KEY (id);


--
-- Name: SCHEMA public; Type: ACL; Schema: -; Owner:  
--


--
-- PostgreSQL database dump complete
--

