Guest User

schema.sql

a guest
Jun 27th, 2020
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. CREATE TABLE public."user" (
  3.     id integer NOT NULL,
  4.     username character varying(255),
  5.     password character varying(255),
  6.     role character varying(255)
  7. );
  8. ALTER TABLE ONLY public."user"
  9.     ADD CONSTRAINT user_pkey PRIMARY KEY (id);
  10. ALTER TABLE ONLY public."user"
  11.     ADD CONSTRAINT user_username_unique UNIQUE (username);
  12.  
  13.  
  14.  
  15. CREATE TABLE public.category (
  16.     id integer NOT NULL,
  17.     type character varying(255) NOT NULL,
  18.     value character varying(255) NOT NULL
  19. );
  20. ALTER TABLE ONLY public.category
  21.     ADD CONSTRAINT category_pkey PRIMARY KEY (id);
  22. ALTER TABLE ONLY public.category
  23.     ADD CONSTRAINT category_value_unique UNIQUE (value);
  24.  
  25.  
  26.  
  27. CREATE TABLE public.content (
  28.     id integer NOT NULL,
  29.     "authorId" integer NOT NULL,
  30.     type character varying(255) NOT NULL,
  31.     "parentId" integer,
  32.     "postId" integer,
  33.     title text,
  34.     link character varying(255),
  35.     thumbnail character varying(255),
  36.     text text NOT NULL
  37. );
  38. ALTER TABLE ONLY public.content
  39.     ADD CONSTRAINT content_pkey PRIMARY KEY (id);
  40. ALTER TABLE ONLY public.content
  41.     ADD CONSTRAINT content_authorid_foreign FOREIGN KEY ("authorId") REFERENCES public."user"(id);
  42. ALTER TABLE ONLY public.content
  43.     ADD CONSTRAINT content_parentid_foreign FOREIGN KEY ("parentId") REFERENCES public.content(id);
  44. ALTER TABLE ONLY public.content
  45.     ADD CONSTRAINT content_postid_foreign FOREIGN KEY ("postId") REFERENCES public.content(id);
  46.  
  47.  
  48.  
  49.  
  50. CREATE TABLE public.vote (
  51.     id integer NOT NULL,
  52.     "voterId" integer NOT NULL,
  53.     "contentId" integer NOT NULL,
  54.     "categoryId" integer NOT NULL
  55. );
  56. ALTER TABLE ONLY public.vote
  57.     ADD CONSTRAINT vote_pkey PRIMARY KEY (id);
  58. ALTER TABLE ONLY public.vote
  59.     ADD CONSTRAINT vote_voterid_contentid_categoryid_unique UNIQUE ("voterId", "contentId", "categoryId");
  60. ALTER TABLE ONLY public.vote
  61.     ADD CONSTRAINT vote_categoryid_foreign FOREIGN KEY ("categoryId") REFERENCES public.category(id);
  62. ALTER TABLE ONLY public.vote
  63.     ADD CONSTRAINT vote_contentid_foreign FOREIGN KEY ("contentId") REFERENCES public.content(id);
  64. ALTER TABLE ONLY public.vote
  65.     ADD CONSTRAINT vote_voterid_foreign FOREIGN KEY ("voterId") REFERENCES public."user"(id);
  66.  
  67.  
  68.  
  69.  
  70. CREATE TABLE public.subscription (
  71.     id integer NOT NULL,
  72.     "subscriberId" integer NOT NULL,
  73.     "idolId" integer,
  74.     "categoryId" integer,
  75.     rank integer DEFAULT 0
  76. );
  77. ALTER TABLE ONLY public.subscription
  78.     ADD CONSTRAINT subscription_pkey PRIMARY KEY (id);
  79. ALTER TABLE ONLY public.subscription
  80.     ADD CONSTRAINT subscription_categoryid_foreign FOREIGN KEY ("categoryId") REFERENCES public.category(id);
  81. ALTER TABLE ONLY public.subscription
  82.     ADD CONSTRAINT subscription_idolid_foreign FOREIGN KEY ("idolId") REFERENCES public."user"(id);
  83. ALTER TABLE ONLY public.subscription
  84.     ADD CONSTRAINT subscription_subscriberid_foreign FOREIGN KEY ("subscriberId") REFERENCES public."user"(id);
Add Comment
Please, Sign In to add comment