api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

blog_postgresql.sql 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. SET statement_timeout = 0;
  5. SET client_encoding = 'UTF8';
  6. SET standard_conforming_strings = on;
  7. SET check_function_bodies = false;
  8. SET client_min_messages = warning;
  9. SET search_path = public, pg_catalog;
  10. SET default_tablespace = '';
  11. SET default_with_oids = false;
  12. --
  13. -- Drop everything
  14. --
  15. DROP TABLE IF EXISTS categories CASCADE;
  16. DROP TABLE IF EXISTS comments CASCADE;
  17. DROP TABLE IF EXISTS post_tags CASCADE;
  18. DROP TABLE IF EXISTS posts CASCADE;
  19. DROP TABLE IF EXISTS tags CASCADE;
  20. DROP TABLE IF EXISTS users CASCADE;
  21. DROP TABLE IF EXISTS countries CASCADE;
  22. DROP TABLE IF EXISTS events CASCADE;
  23. DROP VIEW IF EXISTS tag_usage;
  24. DROP TABLE IF EXISTS products CASCADE;
  25. DROP TABLE IF EXISTS barcodes CASCADE;
  26. --
  27. -- Enables the Postgis extension
  28. --
  29. CREATE EXTENSION IF NOT EXISTS postgis;
  30. --
  31. -- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  32. --
  33. CREATE TABLE categories (
  34. id serial NOT NULL,
  35. name character varying(255) NOT NULL,
  36. icon bytea
  37. );
  38. --
  39. -- Name: comments; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  40. --
  41. CREATE TABLE comments (
  42. id serial NOT NULL,
  43. post_id integer NOT NULL,
  44. message character varying(255) NOT NULL
  45. );
  46. --
  47. -- Name: post_tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  48. --
  49. CREATE TABLE post_tags (
  50. id serial NOT NULL,
  51. post_id integer NOT NULL,
  52. tag_id integer NOT NULL
  53. );
  54. --
  55. -- Name: posts; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  56. --
  57. CREATE TABLE posts (
  58. id serial NOT NULL,
  59. user_id integer NOT NULL,
  60. category_id integer NOT NULL,
  61. content character varying(255) NOT NULL
  62. );
  63. --
  64. -- Name: tags; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  65. --
  66. CREATE TABLE tags (
  67. id serial NOT NULL,
  68. name character varying(255) NOT NULL
  69. );
  70. --
  71. -- Name: users; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  72. --
  73. CREATE TABLE users (
  74. id serial NOT NULL,
  75. username character varying(255) NOT NULL,
  76. password character varying(255) NOT NULL,
  77. location geometry NULL
  78. );
  79. --
  80. -- Name: countries; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  81. --
  82. CREATE TABLE countries (
  83. id serial NOT NULL,
  84. name character varying(255) NOT NULL,
  85. shape geometry NOT NULL
  86. );
  87. --
  88. -- Name: events; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  89. --
  90. CREATE TABLE events (
  91. id serial NOT NULL,
  92. name character varying(255) NOT NULL,
  93. datetime timestamp NOT NULL,
  94. visitors integer NOT NULL
  95. );
  96. --
  97. -- Name: tag_usage; Type: VIEW; Schema: public; Owner: postgres; Tablespace:
  98. --
  99. CREATE VIEW "tag_usage" AS select "name", count("name") AS "count" from "tags", "post_tags" where "tags"."id" = "post_tags"."tag_id" group by "name" order by "count" desc, "name";
  100. --
  101. -- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  102. --
  103. CREATE TABLE products (
  104. id serial NOT NULL,
  105. name character varying(255) NOT NULL,
  106. price decimal(10,2) NOT NULL,
  107. properties jsonb NOT NULL,
  108. created_at timestamp NOT NULL,
  109. deleted_at timestamp NULL
  110. );
  111. --
  112. -- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
  113. --
  114. CREATE TABLE barcodes (
  115. id serial NOT NULL,
  116. product_id integer NOT NULL,
  117. hex character varying(255) NOT NULL,
  118. bin bytea NOT NULL
  119. );
  120. --
  121. -- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres
  122. --
  123. INSERT INTO "categories" ("name", "icon") VALUES
  124. ('announcement', NULL),
  125. ('article', NULL);
  126. --
  127. -- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: postgres
  128. --
  129. INSERT INTO "comments" ("post_id", "message") VALUES
  130. (1, 'great'),
  131. (1, 'fantastic'),
  132. (2, 'thank you'),
  133. (2, 'awesome');
  134. --
  135. -- Data for Name: post_tags; Type: TABLE DATA; Schema: public; Owner: postgres
  136. --
  137. INSERT INTO "post_tags" ("post_id", "tag_id") VALUES
  138. (1, 1),
  139. (1, 2),
  140. (2, 1),
  141. (2, 2);
  142. --
  143. -- Data for Name: posts; Type: TABLE DATA; Schema: public; Owner: postgres
  144. --
  145. INSERT INTO "posts" ("user_id", "category_id", "content") VALUES
  146. (1, 1, 'blog started'),
  147. (1, 2, 'It works!');
  148. --
  149. -- Data for Name: tags; Type: TABLE DATA; Schema: public; Owner: postgres
  150. --
  151. INSERT INTO "tags" ("name") VALUES
  152. ('funny'),
  153. ('important');
  154. --
  155. -- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: postgres
  156. --
  157. INSERT INTO "users" ("username", "password", "location") VALUES
  158. ('user1', 'pass1', NULL),
  159. ('user2', 'pass2', NULL);
  160. --
  161. -- Data for Name: countries; Type: TABLE DATA; Schema: public; Owner: postgres
  162. --
  163. INSERT INTO "countries" ("name", "shape") VALUES
  164. ('Left', ST_GeomFromText('POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))')),
  165. ('Right', ST_GeomFromText('POLYGON ((70 10, 80 40, 60 40, 50 20, 70 10))'));
  166. --
  167. -- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres
  168. --
  169. INSERT INTO "events" ("name", "datetime", "visitors") VALUES
  170. ('Launch', '2016-01-01 13:01:01', 0);
  171. --
  172. -- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres
  173. --
  174. INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES
  175. ('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');
  176. --
  177. -- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres
  178. --
  179. INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES
  180. (1, '00ff01', E'\\x00ff01');
  181. --
  182. -- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  183. --
  184. ALTER TABLE ONLY categories
  185. ADD CONSTRAINT categories_pkey PRIMARY KEY (id);
  186. --
  187. -- Name: comments_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  188. --
  189. ALTER TABLE ONLY comments
  190. ADD CONSTRAINT comments_pkey PRIMARY KEY (id);
  191. --
  192. -- Name: post_tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  193. --
  194. ALTER TABLE ONLY post_tags
  195. ADD CONSTRAINT post_tags_pkey PRIMARY KEY (id);
  196. --
  197. -- Name: post_tags_post_id_tag_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  198. --
  199. ALTER TABLE ONLY post_tags
  200. ADD CONSTRAINT post_tags_post_id_tag_id_key UNIQUE (post_id, tag_id);
  201. --
  202. -- Name: posts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  203. --
  204. ALTER TABLE ONLY posts
  205. ADD CONSTRAINT posts_pkey PRIMARY KEY (id);
  206. --
  207. -- Name: tags_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  208. --
  209. ALTER TABLE ONLY tags
  210. ADD CONSTRAINT tags_pkey PRIMARY KEY (id);
  211. --
  212. -- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  213. --
  214. ALTER TABLE ONLY users
  215. ADD CONSTRAINT users_pkey PRIMARY KEY (id);
  216. --
  217. -- Name: countries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  218. --
  219. ALTER TABLE ONLY countries
  220. ADD CONSTRAINT countries_pkey PRIMARY KEY (id);
  221. --
  222. -- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  223. --
  224. ALTER TABLE ONLY events
  225. ADD CONSTRAINT events_pkey PRIMARY KEY (id);
  226. --
  227. -- Name: products_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  228. --
  229. ALTER TABLE ONLY products
  230. ADD CONSTRAINT products_pkey PRIMARY KEY (id);
  231. --
  232. -- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
  233. --
  234. ALTER TABLE ONLY barcodes
  235. ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id);
  236. --
  237. -- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  238. --
  239. CREATE INDEX comments_post_id_idx ON comments USING btree (post_id);
  240. --
  241. -- Name: post_tags_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  242. --
  243. CREATE INDEX post_tags_post_id_idx ON post_tags USING btree (post_id);
  244. --
  245. -- Name: post_tags_tag_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  246. --
  247. CREATE INDEX post_tags_tag_id_idx ON post_tags USING btree (tag_id);
  248. --
  249. -- Name: posts_category_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  250. --
  251. CREATE INDEX posts_category_id_idx ON posts USING btree (category_id);
  252. --
  253. -- Name: posts_user_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  254. --
  255. CREATE INDEX posts_user_id_idx ON posts USING btree (user_id);
  256. --
  257. -- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
  258. --
  259. CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id);
  260. --
  261. -- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  262. --
  263. ALTER TABLE ONLY comments
  264. ADD CONSTRAINT comments_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id);
  265. --
  266. -- Name: post_tags_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  267. --
  268. ALTER TABLE ONLY post_tags
  269. ADD CONSTRAINT post_tags_post_id_fkey FOREIGN KEY (post_id) REFERENCES posts(id);
  270. --
  271. -- Name: post_tags_tag_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  272. --
  273. ALTER TABLE ONLY post_tags
  274. ADD CONSTRAINT post_tags_tag_id_fkey FOREIGN KEY (tag_id) REFERENCES tags(id);
  275. --
  276. -- Name: posts_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  277. --
  278. ALTER TABLE ONLY posts
  279. ADD CONSTRAINT posts_category_id_fkey FOREIGN KEY (category_id) REFERENCES categories(id);
  280. --
  281. -- Name: posts_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  282. --
  283. ALTER TABLE ONLY posts
  284. ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
  285. --
  286. -- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
  287. --
  288. ALTER TABLE ONLY barcodes
  289. ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id);
  290. --
  291. -- PostgreSQL database dump complete
  292. --