204 lines
5.6 KiB
MySQL
204 lines
5.6 KiB
MySQL
|
--
|
||
|
-- PostgreSQL database dump
|
||
|
--
|
||
|
|
||
|
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;
|
||
|
|
||
|
CREATE FUNCTION public.update_modified_column() RETURNS trigger
|
||
|
LANGUAGE plpgsql
|
||
|
AS $$
|
||
|
BEGIN
|
||
|
NEW.updated_at = CURRENT_TIMESTAMP;
|
||
|
RETURN NEW;
|
||
|
END;
|
||
|
$$;
|
||
|
|
||
|
|
||
|
ALTER FUNCTION public.update_modified_column() OWNER TO wyatt;
|
||
|
|
||
|
SET default_tablespace = '';
|
||
|
|
||
|
SET default_table_access_method = heap;
|
||
|
|
||
|
CREATE TABLE public.authors (
|
||
|
author_id integer NOT NULL,
|
||
|
first_name character varying(50) NOT NULL,
|
||
|
last_name character varying(100) NOT NULL,
|
||
|
created_at timestamp with time zone DEFAULT now(),
|
||
|
updated_at timestamp with time zone DEFAULT now(),
|
||
|
bio text
|
||
|
);
|
||
|
|
||
|
ALTER TABLE public.authors OWNER TO wyatt;
|
||
|
|
||
|
CREATE SEQUENCE public.authors_author_id_seq
|
||
|
AS integer
|
||
|
START WITH 1
|
||
|
INCREMENT BY 1
|
||
|
NO MINVALUE
|
||
|
NO MAXVALUE
|
||
|
CACHE 1;
|
||
|
|
||
|
|
||
|
ALTER SEQUENCE public.authors_author_id_seq OWNER TO wyatt;
|
||
|
|
||
|
ALTER SEQUENCE public.authors_author_id_seq OWNED BY public.authors.author_id;
|
||
|
|
||
|
CREATE TABLE public.comments (
|
||
|
comment_id integer NOT NULL,
|
||
|
post_id integer,
|
||
|
body character varying(2000) NOT NULL,
|
||
|
name character varying(200) NOT NULL,
|
||
|
created_at timestamp with time zone DEFAULT now(),
|
||
|
deleted_at timestamp with time zone
|
||
|
);
|
||
|
|
||
|
|
||
|
ALTER TABLE public.comments OWNER TO wyatt;
|
||
|
|
||
|
CREATE SEQUENCE public.comments_comment_id_seq
|
||
|
AS integer
|
||
|
START WITH 1
|
||
|
INCREMENT BY 1
|
||
|
NO MINVALUE
|
||
|
NO MAXVALUE
|
||
|
CACHE 1;
|
||
|
|
||
|
|
||
|
ALTER SEQUENCE public.comments_comment_id_seq OWNER TO wyatt;
|
||
|
|
||
|
ALTER SEQUENCE public.comments_comment_id_seq OWNED BY public.comments.comment_id;
|
||
|
|
||
|
CREATE TABLE public.logs (
|
||
|
log_id integer NOT NULL,
|
||
|
task_id integer,
|
||
|
created_at timestamp with time zone DEFAULT now(),
|
||
|
task_status text,
|
||
|
finished_at timestamp with time zone DEFAULT now()
|
||
|
);
|
||
|
|
||
|
|
||
|
ALTER TABLE public.logs OWNER TO wyatt;
|
||
|
|
||
|
CREATE SEQUENCE public.logs_log_id_seq
|
||
|
AS integer
|
||
|
START WITH 1
|
||
|
INCREMENT BY 1
|
||
|
NO MINVALUE
|
||
|
NO MAXVALUE
|
||
|
CACHE 1;
|
||
|
|
||
|
|
||
|
ALTER SEQUENCE public.logs_log_id_seq OWNER TO wyatt;
|
||
|
|
||
|
ALTER SEQUENCE public.logs_log_id_seq OWNED BY public.logs.log_id;
|
||
|
|
||
|
CREATE TABLE public.posts (
|
||
|
post_id integer NOT NULL,
|
||
|
author_id integer,
|
||
|
title text NOT NULL,
|
||
|
body text NOT NULL,
|
||
|
created_at timestamp with time zone DEFAULT now(),
|
||
|
updated_at timestamp with time zone DEFAULT now(),
|
||
|
deleted_at timestamp with time zone,
|
||
|
filename text NOT NULL,
|
||
|
view_count bigint DEFAULT 0 NOT NULL
|
||
|
);
|
||
|
|
||
|
|
||
|
ALTER TABLE public.posts OWNER TO wyatt;
|
||
|
|
||
|
CREATE SEQUENCE public.posts_post_id_seq
|
||
|
AS integer
|
||
|
START WITH 1
|
||
|
INCREMENT BY 1
|
||
|
NO MINVALUE
|
||
|
NO MAXVALUE
|
||
|
CACHE 1;
|
||
|
|
||
|
|
||
|
ALTER SEQUENCE public.posts_post_id_seq OWNER TO wyatt;
|
||
|
|
||
|
ALTER SEQUENCE public.posts_post_id_seq OWNED BY public.posts.post_id;
|
||
|
|
||
|
CREATE TABLE public.tasks (
|
||
|
task_id integer NOT NULL,
|
||
|
task_name character varying(100),
|
||
|
schedule text,
|
||
|
is_active boolean,
|
||
|
created_at timestamp with time zone DEFAULT now(),
|
||
|
updated_at timestamp with time zone DEFAULT now(),
|
||
|
deleted_at timestamp with time zone
|
||
|
);
|
||
|
|
||
|
|
||
|
ALTER TABLE public.tasks OWNER TO wyatt;
|
||
|
|
||
|
CREATE SEQUENCE public.tasks_task_id_seq
|
||
|
AS integer
|
||
|
START WITH 1
|
||
|
INCREMENT BY 1
|
||
|
NO MINVALUE
|
||
|
NO MAXVALUE
|
||
|
CACHE 1;
|
||
|
|
||
|
|
||
|
ALTER SEQUENCE public.tasks_task_id_seq OWNER TO wyatt;
|
||
|
|
||
|
ALTER SEQUENCE public.tasks_task_id_seq OWNED BY public.tasks.task_id;
|
||
|
|
||
|
ALTER TABLE ONLY public.authors ALTER COLUMN author_id SET DEFAULT nextval('public.authors_author_id_seq'::regclass);
|
||
|
|
||
|
ALTER TABLE ONLY public.comments ALTER COLUMN comment_id SET DEFAULT nextval('public.comments_comment_id_seq'::regclass);
|
||
|
|
||
|
ALTER TABLE ONLY public.logs ALTER COLUMN log_id SET DEFAULT nextval('public.logs_log_id_seq'::regclass);
|
||
|
|
||
|
ALTER TABLE ONLY public.posts ALTER COLUMN post_id SET DEFAULT nextval('public.posts_post_id_seq'::regclass);
|
||
|
|
||
|
ALTER TABLE ONLY public.tasks ALTER COLUMN task_id SET DEFAULT nextval('public.tasks_task_id_seq'::regclass);
|
||
|
|
||
|
ALTER TABLE ONLY public.authors
|
||
|
ADD CONSTRAINT authors_pkey PRIMARY KEY (author_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.comments
|
||
|
ADD CONSTRAINT comments_pkey PRIMARY KEY (comment_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.logs
|
||
|
ADD CONSTRAINT logs_pkey PRIMARY KEY (log_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.posts
|
||
|
ADD CONSTRAINT posts_pkey PRIMARY KEY (post_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.tasks
|
||
|
ADD CONSTRAINT tasks_pkey PRIMARY KEY (task_id);
|
||
|
|
||
|
CREATE INDEX idx_author_first_name ON public.authors USING btree (first_name);
|
||
|
|
||
|
CREATE INDEX idx_author_last_name ON public.authors USING btree (last_name);
|
||
|
|
||
|
CREATE INDEX idx_posts_title ON public.posts USING btree (title);
|
||
|
|
||
|
CREATE TRIGGER update_authors_modtime BEFORE UPDATE ON public.authors FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();
|
||
|
|
||
|
CREATE TRIGGER update_posts_modtime BEFORE UPDATE ON public.posts FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();
|
||
|
|
||
|
CREATE TRIGGER update_tasks_modtime BEFORE UPDATE ON public.tasks FOR EACH ROW EXECUTE FUNCTION public.update_modified_column();
|
||
|
|
||
|
ALTER TABLE ONLY public.comments
|
||
|
ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES public.posts(post_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.logs
|
||
|
ADD CONSTRAINT logs_task_id_fkey FOREIGN KEY (task_id) REFERENCES public.tasks(task_id);
|
||
|
|
||
|
ALTER TABLE ONLY public.posts
|
||
|
ADD CONSTRAINT posts_author_id_fkey FOREIGN KEY (author_id) REFERENCES public.authors(author_id);
|