You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

01_init.sql 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. --
  2. -- PostgreSQL database dump
  3. --
  4. SET statement_timeout = 0;
  5. SET lock_timeout = 0;
  6. SET client_encoding = 'UTF8';
  7. SET standard_conforming_strings = on;
  8. SET check_function_bodies = false;
  9. SET client_min_messages = warning;
  10. --
  11. -- Name: plpgsql; Type: EXTENSION; Schema: -;
  12. --
  13. CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
  14. --
  15. -- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -;
  16. --
  17. COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
  18. --
  19. -- Name: unaccent; Type: EXTENSION; Schema: -;
  20. --
  21. CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
  22. --
  23. -- Name: EXTENSION unaccent; Type: COMMENT; Schema: -;
  24. --
  25. COMMENT ON EXTENSION unaccent IS 'text search dictionary that removes accents';
  26. --
  27. -- Name: uuid-ossp; Type: EXTENSION; Schema: -;
  28. --
  29. CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;
  30. --
  31. -- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -;
  32. --
  33. COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';
  34. SET search_path = public, pg_catalog;
  35. --
  36. -- Name: get_uuid(); Type: FUNCTION; Schema: public;
  37. --
  38. CREATE FUNCTION get_uuid() RETURNS uuid
  39. LANGUAGE sql
  40. AS $$SELECT * FROM uuid_generate_v1()$$;
  41. --
  42. -- Name: lu_on_row_delete(); Type: FUNCTION; Schema: public;
  43. --
  44. CREATE FUNCTION lu_on_row_delete() RETURNS trigger
  45. LANGUAGE plpgsql
  46. AS $$BEGIN
  47. INSERT INTO lu_entities_history ("table", "data") VALUES(TG_TABLE_NAME, to_json(OLD));
  48. RETURN OLD;
  49. END$$;
  50. --
  51. -- Name: lu_on_row_update(); Type: FUNCTION; Schema: public;
  52. --
  53. CREATE FUNCTION lu_on_row_update() RETURNS trigger
  54. LANGUAGE plpgsql
  55. AS $$BEGIN
  56. NEW.updated_at := now();
  57. INSERT INTO lu_entities_history ("table", "data") VALUES(TG_TABLE_NAME, to_json(OLD));
  58. return NEW;
  59. END$$;
  60. --
  61. -- Name: lu_text_match(text, text); Type: FUNCTION; Schema: public;
  62. --
  63. CREATE FUNCTION lu_text_match(query text, data text) RETURNS boolean
  64. LANGUAGE sql
  65. AS $$SELECT unaccent(data) ILIKE ('%' || unaccent(query) || '%') AS result$$;
  66. --
  67. -- Name: lu_texts_match(text, text[]); Type: FUNCTION; Schema: public;
  68. --
  69. CREATE FUNCTION lu_texts_match(query text, VARIADIC data text[]) RETURNS boolean
  70. LANGUAGE sql
  71. AS $$
  72. WITH q AS (
  73. SELECT unnest(data) AS d UNION SELECT array_to_string(data, ' ')
  74. )
  75. SELECT lu_text_match(query, d.d) AS res FROM q d ORDER BY res DESC LIMIT 1
  76. $$;
  77. SET default_tablespace = '';
  78. SET default_with_oids = false;
  79. --
  80. -- Name: lu_entities_history; Type: TABLE; Schema: public; ; Tablespace:
  81. --
  82. CREATE TABLE lu_entities_history (
  83. id uuid DEFAULT get_uuid() NOT NULL,
  84. "table" character varying(128) NOT NULL,
  85. data json,
  86. date timestamp with time zone DEFAULT now() NOT NULL
  87. );
  88. --
  89. -- Name: lu_entities_history_pkey; Type: CONSTRAINT; Schema: public; ; Tablespace:
  90. --
  91. ALTER TABLE ONLY lu_entities_history
  92. ADD CONSTRAINT lu_entities_history_pkey PRIMARY KEY (id);
  93. --
  94. -- PostgreSQL database dump complete
  95. --