postgres.sql 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. SET statement_timeout = 0;
  5. SET client_encoding = 'UTF8';
  6. SET standard_conforming_strings = off;
  7. SET check_function_bodies = false;
  8. SET client_min_messages = warning;
  9. SET escape_string_warning = off;
  10. --
  11. -- Name: anotherschema; Type: SCHEMA; Schema: -; Owner: -
  12. --
  13. DROP SCHEMA IF EXISTS anotherschema CASCADE;
  14. CREATE SCHEMA anotherschema;
  15. SET search_path = anotherschema, pg_catalog;
  16. SET default_tablespace = '';
  17. SET default_with_oids = false;
  18. --
  19. -- Name: users; Type: TABLE; Schema: anotherschema; Owner: -; Tablespace:
  20. --
  21. DROP TABLE IF EXISTS users CASCADE;
  22. CREATE TABLE users (
  23. name character varying(30),
  24. email character varying(50),
  25. created_at timestamp without time zone DEFAULT now(),
  26. id integer NOT NULL
  27. );
  28. --
  29. -- Name: users_id_seq; Type: SEQUENCE; Schema: anotherschema; Owner: -
  30. --
  31. CREATE SEQUENCE users_id_seq
  32. START WITH 1
  33. INCREMENT BY 1
  34. NO MINVALUE
  35. NO MAXVALUE
  36. CACHE 1;
  37. --
  38. -- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: anotherschema; Owner: -
  39. --
  40. ALTER SEQUENCE users_id_seq OWNED BY users.id;
  41. SET search_path = public, pg_catalog;
  42. --
  43. -- Name: seqnames; Type: TABLE; Schema: public; Owner: -; Tablespace:
  44. --
  45. DROP TABLE IF EXISTS seqnames CASCADE;
  46. CREATE TABLE seqnames (
  47. name character varying(30),
  48. pk_id integer NOT NULL
  49. );
  50. --
  51. -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  52. --
  53. CREATE SEQUENCE seqnames_pk_id_seq
  54. START WITH 1
  55. INCREMENT BY 1
  56. NO MINVALUE
  57. NO MAXVALUE
  58. CACHE 1;
  59. --
  60. -- Name: seqnames_pk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  61. --
  62. ALTER SEQUENCE seqnames_pk_id_seq OWNED BY seqnames.pk_id;
  63. --
  64. -- Name: empty_table; Type: TABLE; Schema: public; Owner: -; Tablespace:
  65. --
  66. DROP TABLE IF EXISTS empty_table CASCADE;
  67. CREATE TABLE empty_table (
  68. id integer NOT NULL,
  69. field character varying
  70. );
  71. --
  72. -- Name: empty_table_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  73. --
  74. CREATE SEQUENCE empty_table_id_seq
  75. START WITH 1
  76. INCREMENT BY 1
  77. NO MINVALUE
  78. NO MAXVALUE
  79. CACHE 1;
  80. --
  81. -- Name: empty_table_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  82. --
  83. ALTER SEQUENCE empty_table_id_seq OWNED BY empty_table.id;
  84. --
  85. -- Name: groups; Type: TABLE; Schema: public; Owner: -; Tablespace:
  86. --
  87. DROP TABLE IF EXISTS groups CASCADE;
  88. CREATE TABLE groups (
  89. name character varying(50),
  90. enabled boolean,
  91. created_at timestamp without time zone DEFAULT now(),
  92. id integer NOT NULL
  93. );
  94. --
  95. -- Name: groups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  96. --
  97. CREATE SEQUENCE groups_id_seq
  98. START WITH 1
  99. INCREMENT BY 1
  100. NO MAXVALUE
  101. NO MINVALUE
  102. CACHE 1;
  103. --
  104. -- Name: groups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  105. --
  106. ALTER SEQUENCE groups_id_seq OWNED BY groups.id;
  107. --
  108. -- Name: permissions; Type: TABLE; Schema: public; Owner: -; Tablespace:
  109. --
  110. DROP TABLE IF EXISTS permissions CASCADE;
  111. CREATE TABLE permissions (
  112. user_id integer,
  113. group_id integer,
  114. role character varying(10),
  115. id integer NOT NULL
  116. );
  117. --
  118. -- Name: permissions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  119. --
  120. CREATE SEQUENCE permissions_id_seq
  121. START WITH 1
  122. INCREMENT BY 1
  123. NO MAXVALUE
  124. NO MINVALUE
  125. CACHE 1;
  126. --
  127. -- Name: permissions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  128. --
  129. ALTER SEQUENCE permissions_id_seq OWNED BY permissions.id;
  130. --
  131. -- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace:
  132. --
  133. DROP TABLE IF EXISTS users CASCADE;
  134. CREATE TABLE users (
  135. name character varying(30),
  136. email character varying(50),
  137. created_at timestamp without time zone DEFAULT now(),
  138. id integer NOT NULL
  139. );
  140. --
  141. -- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: -
  142. --
  143. CREATE SEQUENCE users_id_seq
  144. START WITH 1
  145. INCREMENT BY 1
  146. NO MAXVALUE
  147. NO MINVALUE
  148. CACHE 1;
  149. --
  150. -- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
  151. --
  152. ALTER SEQUENCE users_id_seq OWNED BY users.id;
  153. SET search_path = anotherschema, pg_catalog;
  154. --
  155. -- Name: id; Type: DEFAULT; Schema: anotherschema; Owner: -
  156. --
  157. ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass);
  158. SET search_path = public, pg_catalog;
  159. --
  160. -- Name:pk_id; Type: DEFAULT; Schema: public; Owner: -
  161. --
  162. ALTER TABLE ONLY seqnames ALTER COLUMN pk_id SET DEFAULT nextval('seqnames_pk_id_seq'::regclass);
  163. --
  164. -- Name: id; Type: DEFAULT; Schema: public; Owner: -
  165. --
  166. ALTER TABLE ONLY empty_table ALTER COLUMN id SET DEFAULT nextval('empty_table_id_seq'::regclass);
  167. --
  168. -- Name: id; Type: DEFAULT; Schema: public; Owner: -
  169. --
  170. ALTER TABLE ONLY groups ALTER COLUMN id SET DEFAULT nextval('groups_id_seq'::regclass);
  171. --
  172. -- Name: id; Type: DEFAULT; Schema: public; Owner: -
  173. --
  174. ALTER TABLE ONLY permissions ALTER COLUMN id SET DEFAULT nextval('permissions_id_seq'::regclass);
  175. --
  176. -- Name: id; Type: DEFAULT; Schema: public; Owner: -
  177. --
  178. ALTER TABLE ONLY users ALTER COLUMN id SET DEFAULT nextval('users_id_seq'::regclass);
  179. SET search_path = anotherschema, pg_catalog;
  180. --
  181. -- Data for Name: users; Type: TABLE DATA; Schema: anotherschema; Owner: -
  182. --
  183. COPY users (name, email, created_at, id) FROM stdin;
  184. andrew schemauser@example.org 2015-10-13 07:26:51.398693 1
  185. \.
  186. --
  187. -- Name: users_id_seq; Type: SEQUENCE SET; Schema: anotherschema; Owner: -
  188. --
  189. SELECT pg_catalog.setval('users_id_seq', 1, true);
  190. SET search_path = public, pg_catalog;
  191. --
  192. -- Data for Name: empty_table; Type: TABLE DATA; Schema: public; Owner: -
  193. --
  194. COPY empty_table (id, field) FROM stdin;
  195. \.
  196. --
  197. -- Name: seqnames_pk_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
  198. --
  199. SELECT pg_catalog.setval('seqnames_pk_id_seq', 1, false);
  200. --
  201. -- Name: empty_table_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
  202. --
  203. SELECT pg_catalog.setval('empty_table_id_seq', 1, false);
  204. --
  205. -- Data for Name: groups; Type: TABLE DATA; Schema: public; Owner: -
  206. --
  207. COPY groups (name, enabled, created_at, id) FROM stdin;
  208. coders t 2012-02-02 22:33:30.807 1
  209. jazzman f 2012-02-02 22:33:35.271 2
  210. \.
  211. --
  212. -- Name: groups_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
  213. --
  214. SELECT pg_catalog.setval('groups_id_seq', 2, true);
  215. --
  216. -- Data for Name: permissions; Type: TABLE DATA; Schema: public; Owner: -
  217. --
  218. COPY permissions (user_id, group_id, role, id) FROM stdin;
  219. 1 1 member 1
  220. 2 1 member 2
  221. 3 2 member 9
  222. 4 2 admin 10
  223. \.
  224. --
  225. -- Name: permissions_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
  226. --
  227. SELECT pg_catalog.setval('permissions_id_seq', 10, true);
  228. --
  229. -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: -
  230. --
  231. COPY users (name, email, created_at, id) FROM stdin;
  232. davert davert@mail.ua \N 1
  233. nick nick@mail.ua 2012-02-02 22:30:31.748 2
  234. miles miles@davis.com 2012-02-02 22:30:52.166 3
  235. bird charlie@parker.com 2012-02-02 22:32:13.107 4
  236. \.
  237. --
  238. -- Name: users_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
  239. --
  240. SELECT pg_catalog.setval('users_id_seq', 4, true);
  241. SET search_path = anotherschema, pg_catalog;
  242. --
  243. -- Name: u1; Type: CONSTRAINT; Schema: anotherschema; Owner: -; Tablespace:
  244. --
  245. ALTER TABLE ONLY users
  246. ADD CONSTRAINT u1 PRIMARY KEY (id);
  247. SET search_path = public, pg_catalog;
  248. --
  249. -- Name: g1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  250. --
  251. ALTER TABLE ONLY seqnames
  252. ADD CONSTRAINT s1 PRIMARY KEY (pk_id);
  253. --
  254. -- Name: g1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  255. --
  256. ALTER TABLE ONLY groups
  257. ADD CONSTRAINT g1 PRIMARY KEY (id);
  258. --
  259. -- Name: p1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  260. --
  261. ALTER TABLE ONLY permissions
  262. ADD CONSTRAINT p1 PRIMARY KEY (id);
  263. --
  264. -- Name: u1; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
  265. --
  266. ALTER TABLE ONLY users
  267. ADD CONSTRAINT u1 PRIMARY KEY (id);
  268. --
  269. -- Name: pf1; Type: FK CONSTRAINT; Schema: public; Owner: -
  270. --
  271. ALTER TABLE ONLY permissions
  272. ADD CONSTRAINT pf1 FOREIGN KEY (user_id) REFERENCES users(id);
  273. --
  274. -- Name: pg1; Type: FK CONSTRAINT; Schema: public; Owner: -
  275. --
  276. ALTER TABLE ONLY permissions
  277. ADD CONSTRAINT pg1 FOREIGN KEY (group_id) REFERENCES groups(id);
  278. --
  279. -- start test for triggers with $$ syntax
  280. --
  281. INSERT INTO users (name, email) VALUES ('This $$ should work', 'user@example.org');
  282. CREATE OR REPLACE FUNCTION upd_timestamp() RETURNS TRIGGER
  283. LANGUAGE plpgsql
  284. AS
  285. $$
  286. BEGIN
  287. NEW.created_at = CURRENT_TIMESTAMP;
  288. RETURN NEW;
  289. END;
  290. $$;
  291. -- Test $$ opening quote when is not at the beginning of the line.
  292. CREATE OR REPLACE FUNCTION upd_timestamp() RETURNS TRIGGER
  293. LANGUAGE plpgsql
  294. AS $$
  295. BEGIN
  296. NEW.created_at = CURRENT_TIMESTAMP;
  297. RETURN NEW;
  298. END;
  299. $$;
  300. INSERT INTO users (name, email) VALUES ('This should work as well', 'user2@example.org');
  301. --
  302. -- end test for triggers with $$ syntax
  303. --
  304. CREATE TABLE "composite_pk" (
  305. "group_id" INTEGER NOT NULL,
  306. "id" INTEGER NOT NULL,
  307. "status" VARCHAR NOT NULL,
  308. PRIMARY KEY ("group_id", "id")
  309. );
  310. CREATE TABLE "no_pk" (
  311. "status" VARCHAR NOT NULL
  312. );
  313. CREATE TABLE "order" (
  314. "id" INTEGER NOT NULL PRIMARY KEY,
  315. "name" VARCHAR NOT NULL,
  316. "status" VARCHAR NOT NULL
  317. );
  318. insert into "order"("id","name","status") values (1,'main', 'open');
  319. -- Custom Types
  320. DROP TYPE IF EXISTS composite_type;
  321. CREATE TYPE composite_type AS (
  322. a decimal,
  323. b decimal
  324. );
  325. DROP TYPE IF EXISTS enum_type;
  326. CREATE TYPE enum_type AS ENUM (
  327. 'Mon',
  328. 'Tue',
  329. 'Wed',
  330. 'Thu',
  331. 'Fri',
  332. 'Sat',
  333. 'Sun'
  334. );
  335. DROP TYPE IF EXISTS range_type;
  336. CREATE TYPE range_type AS range (subtype = time);
  337. DROP TYPE IF EXISTS base_type;
  338. CREATE TYPE base_type;
  339. -- --
  340. -- PostgreSQL database dump complete
  341. --