Script.txt 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. -- DROP SCHEMA public;
  2. CREATE SCHEMA public AUTHORIZATION pg_database_owner;
  3. -- DROP SEQUENCE public.curses_id_curse_seq;
  4. CREATE SEQUENCE public.curses_id_curse_seq
  5. INCREMENT BY 1
  6. MINVALUE 1
  7. MAXVALUE 2147483647
  8. START 1
  9. CACHE 1
  10. NO CYCLE;
  11. -- DROP SEQUENCE public.curses_id_curse_seq1;
  12. CREATE SEQUENCE public.curses_id_curse_seq1
  13. INCREMENT BY 1
  14. MINVALUE 1
  15. MAXVALUE 2147483647
  16. START 1
  17. CACHE 1
  18. NO CYCLE;
  19. -- DROP SEQUENCE public.gender_id_gender_seq;
  20. CREATE SEQUENCE public.gender_id_gender_seq
  21. INCREMENT BY 1
  22. MINVALUE 1
  23. MAXVALUE 2147483647
  24. START 1
  25. CACHE 1
  26. NO CYCLE;
  27. -- DROP SEQUENCE public.gender_id_gender_seq1;
  28. CREATE SEQUENCE public.gender_id_gender_seq1
  29. INCREMENT BY 1
  30. MINVALUE 1
  31. MAXVALUE 2147483647
  32. START 1
  33. CACHE 1
  34. NO CYCLE;
  35. -- DROP SEQUENCE public.subjects_id_subject_seq;
  36. CREATE SEQUENCE public.subjects_id_subject_seq
  37. INCREMENT BY 1
  38. MINVALUE 1
  39. MAXVALUE 2147483647
  40. START 1
  41. CACHE 1
  42. NO CYCLE;
  43. -- DROP SEQUENCE public.subjects_id_subject_seq1;
  44. CREATE SEQUENCE public.subjects_id_subject_seq1
  45. INCREMENT BY 1
  46. MINVALUE 1
  47. MAXVALUE 2147483647
  48. START 1
  49. CACHE 1
  50. NO CYCLE;
  51. -- DROP SEQUENCE public.teacher_curses_id_teacher_curses_seq;
  52. CREATE SEQUENCE public.teacher_curses_id_teacher_curses_seq
  53. INCREMENT BY 1
  54. MINVALUE 1
  55. MAXVALUE 2147483647
  56. START 1
  57. CACHE 1
  58. NO CYCLE;
  59. -- DROP SEQUENCE public.teacher_curses_id_teacher_curses_seq1;
  60. CREATE SEQUENCE public.teacher_curses_id_teacher_curses_seq1
  61. INCREMENT BY 1
  62. MINVALUE 1
  63. MAXVALUE 2147483647
  64. START 1
  65. CACHE 1
  66. NO CYCLE;
  67. -- DROP SEQUENCE public.teacher_subjects_id_teacher_subjects_seq;
  68. CREATE SEQUENCE public.teacher_subjects_id_teacher_subjects_seq
  69. INCREMENT BY 1
  70. MINVALUE 1
  71. MAXVALUE 2147483647
  72. START 1
  73. CACHE 1
  74. NO CYCLE;
  75. -- DROP SEQUENCE public.teacher_subjects_id_teacher_subjects_seq1;
  76. CREATE SEQUENCE public.teacher_subjects_id_teacher_subjects_seq1
  77. INCREMENT BY 1
  78. MINVALUE 1
  79. MAXVALUE 2147483647
  80. START 1
  81. CACHE 1
  82. NO CYCLE;
  83. -- DROP SEQUENCE public.teachers_id_teacher_seq;
  84. CREATE SEQUENCE public.teachers_id_teacher_seq
  85. INCREMENT BY 1
  86. MINVALUE 1
  87. MAXVALUE 2147483647
  88. START 1
  89. CACHE 1
  90. NO CYCLE;
  91. -- DROP SEQUENCE public.teachers_id_teacher_seq1;
  92. CREATE SEQUENCE public.teachers_id_teacher_seq1
  93. INCREMENT BY 1
  94. MINVALUE 1
  95. MAXVALUE 2147483647
  96. START 1
  97. CACHE 1
  98. NO CYCLE;
  99. -- DROP SEQUENCE public.user_curses_id_curse_seq;
  100. CREATE SEQUENCE public.user_curses_id_curse_seq
  101. INCREMENT BY 1
  102. MINVALUE 1
  103. MAXVALUE 2147483647
  104. START 1
  105. CACHE 1
  106. NO CYCLE;
  107. -- DROP SEQUENCE public.user_curses_list_user_curses_id_seq;
  108. CREATE SEQUENCE public.user_curses_list_user_curses_id_seq
  109. INCREMENT BY 1
  110. MINVALUE 1
  111. MAXVALUE 2147483647
  112. START 1
  113. CACHE 1
  114. NO CYCLE;
  115. -- DROP SEQUENCE public.user_data_id_data_seq;
  116. CREATE SEQUENCE public.user_data_id_data_seq
  117. INCREMENT BY 1
  118. MINVALUE 1
  119. MAXVALUE 2147483647
  120. START 1
  121. CACHE 1
  122. NO CYCLE;
  123. -- DROP SEQUENCE public.users_id_user_seq;
  124. CREATE SEQUENCE public.users_id_user_seq
  125. INCREMENT BY 1
  126. MINVALUE 1
  127. MAXVALUE 2147483647
  128. START 1
  129. CACHE 1
  130. NO CYCLE;-- public.curses определение
  131. -- Drop table
  132. -- DROP TABLE public.curses;
  133. CREATE TABLE public.curses (
  134. id_curse int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  135. curse varchar NOT NULL,
  136. CONSTRAINT curses_pk PRIMARY KEY (id_curse)
  137. );
  138. -- public.gender определение
  139. -- Drop table
  140. -- DROP TABLE public.gender;
  141. CREATE TABLE public.gender (
  142. id_gender int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  143. gender varchar NOT NULL,
  144. CONSTRAINT gender_pk PRIMARY KEY (id_gender)
  145. );
  146. CREATE UNIQUE INDEX gender_id_gender_idx ON public.gender USING btree (id_gender);
  147. -- public.subjects определение
  148. -- Drop table
  149. -- DROP TABLE public.subjects;
  150. CREATE TABLE public.subjects (
  151. id_subject int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  152. subject varchar NOT NULL,
  153. CONSTRAINT subjects_pk PRIMARY KEY (id_subject)
  154. );
  155. -- public.user_curses определение
  156. -- Drop table
  157. -- DROP TABLE public.user_curses;
  158. CREATE TABLE public.user_curses (
  159. curse_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  160. curse_name varchar NOT NULL,
  161. curse_time int4 NOT NULL,
  162. CONSTRAINT user_curses_pk PRIMARY KEY (curse_id)
  163. );
  164. -- public.users определение
  165. -- Drop table
  166. -- DROP TABLE public.users;
  167. CREATE TABLE public.users (
  168. id_user int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  169. "role" varchar NOT NULL,
  170. CONSTRAINT users_pk PRIMARY KEY (id_user)
  171. );
  172. -- public.teachers определение
  173. -- Drop table
  174. -- DROP TABLE public.teachers;
  175. CREATE TABLE public.teachers (
  176. id_teacher int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  177. surname varchar NOT NULL,
  178. "name" varchar NOT NULL,
  179. softname varchar NULL,
  180. id_gender int4 NOT NULL,
  181. birthday date NOT NULL,
  182. experience int4 NOT NULL,
  183. e_mail varchar NOT NULL,
  184. phone varchar NULL,
  185. CONSTRAINT teachers_pk PRIMARY KEY (id_teacher),
  186. CONSTRAINT teachers_fk FOREIGN KEY (id_gender) REFERENCES public.gender(id_gender)
  187. );
  188. -- public.user_curses_list определение
  189. -- Drop table
  190. -- DROP TABLE public.user_curses_list;
  191. CREATE TABLE public.user_curses_list (
  192. user_curses_id int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  193. id_teacher int4 NOT NULL,
  194. curse_id int4 NOT NULL,
  195. CONSTRAINT user_curses_list_pk PRIMARY KEY (user_curses_id),
  196. CONSTRAINT user_curses_list_teachers_fk FOREIGN KEY (id_teacher) REFERENCES public.teachers(id_teacher),
  197. CONSTRAINT user_curses_list_user_curses_fk FOREIGN KEY (curse_id) REFERENCES public.user_curses(curse_id)
  198. );
  199. -- public.user_data определение
  200. -- Drop table
  201. -- DROP TABLE public.user_data;
  202. CREATE TABLE public.user_data (
  203. id_data int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  204. login varchar NOT NULL,
  205. "password" varchar NOT NULL,
  206. id_teacher int4 NULL,
  207. id_user int4 NOT NULL,
  208. CONSTRAINT user_data_pk PRIMARY KEY (id_data),
  209. CONSTRAINT user_data_teachers_fk FOREIGN KEY (id_teacher) REFERENCES public.teachers(id_teacher),
  210. CONSTRAINT user_data_users_fk FOREIGN KEY (id_user) REFERENCES public.users(id_user)
  211. );
  212. -- public.teacher_curses определение
  213. -- Drop table
  214. -- DROP TABLE public.teacher_curses;
  215. CREATE TABLE public.teacher_curses (
  216. id_teacher_curses int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  217. id_teacher int4 NOT NULL,
  218. id_curse int4 NOT NULL,
  219. hours int4 NOT NULL,
  220. CONSTRAINT teacher_curses_pk PRIMARY KEY (id_teacher_curses),
  221. CONSTRAINT teacher_curses_fk FOREIGN KEY (id_teacher) REFERENCES public.teachers(id_teacher),
  222. CONSTRAINT teacher_curses_fk_1 FOREIGN KEY (id_curse) REFERENCES public.curses(id_curse)
  223. );
  224. -- public.teacher_subjects определение
  225. -- Drop table
  226. -- DROP TABLE public.teacher_subjects;
  227. CREATE TABLE public.teacher_subjects (
  228. id_teacher_subjects int4 NOT NULL GENERATED ALWAYS AS IDENTITY( INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START 1 CACHE 1 NO CYCLE),
  229. id_teacher int4 NOT NULL,
  230. id_subject int4 NOT NULL,
  231. CONSTRAINT teacher_subjects_pk PRIMARY KEY (id_teacher_subjects),
  232. CONSTRAINT teacher_subjects_fk FOREIGN KEY (id_teacher) REFERENCES public.teachers(id_teacher),
  233. CONSTRAINT teacher_subjects_fk_1 FOREIGN KEY (id_subject) REFERENCES public.subjects(id_subject)
  234. );