dbschema.sql 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. -- public.admin_users definition
  2. -- Drop table
  3. -- DROP TABLE public.admin_users;
  4. CREATE TABLE public.admin_users (
  5. id serial4 NOT NULL,
  6. username text NOT NULL,
  7. password_hash text NOT NULL,
  8. "role" text DEFAULT 'user'::text NULL,
  9. CONSTRAINT admin_users_pkey PRIMARY KEY (id),
  10. CONSTRAINT admin_users_username_key UNIQUE (username)
  11. );
  12. -- public.blacklisted_domains definition
  13. -- Drop table
  14. -- DROP TABLE public.blacklisted_domains;
  15. CREATE TABLE public.blacklisted_domains (
  16. id serial4 NOT NULL,
  17. "domain" text NULL,
  18. CONSTRAINT blacklisted_domains_domain_key UNIQUE (domain),
  19. CONSTRAINT blacklisted_domains_pkey PRIMARY KEY (id)
  20. );
  21. -- public.media_files definition
  22. -- Drop table
  23. -- DROP TABLE public.media_files;
  24. CREATE TABLE public.media_files (
  25. id serial4 NOT NULL,
  26. source_url text NOT NULL,
  27. media_url text NOT NULL,
  28. media_type varchar(50) NULL,
  29. alt_text text NULL,
  30. discovered_at timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  31. CONSTRAINT media_files_media_url_key UNIQUE (media_url),
  32. CONSTRAINT media_files_pkey PRIMARY KEY (id)
  33. );
  34. CREATE INDEX idx_media_alt_trgm ON public.media_files USING gin (alt_text gin_trgm_ops);
  35. CREATE INDEX idx_media_url_trgm ON public.media_files USING gin (source_url gin_trgm_ops);
  36. -- public.submitted_urls definition
  37. -- Drop table
  38. -- DROP TABLE public.submitted_urls;
  39. CREATE TABLE public.submitted_urls (
  40. id serial4 NOT NULL,
  41. url text NULL,
  42. submitted_at timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  43. CONSTRAINT submitted_urls_pkey PRIMARY KEY (id)
  44. );
  45. -- public.zones definition
  46. -- Drop table
  47. -- DROP TABLE public.zones;
  48. CREATE TABLE public.zones (
  49. id serial4 NOT NULL,
  50. zone_name text NOT NULL,
  51. dns_server_ip text NULL,
  52. last_synced timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  53. is_active bool DEFAULT true NULL,
  54. CONSTRAINT zones_pkey PRIMARY KEY (id),
  55. CONSTRAINT zones_zone_name_key UNIQUE (zone_name)
  56. );
  57. -- public.activity_logs definition
  58. -- Drop table
  59. -- DROP TABLE public.activity_logs;
  60. CREATE TABLE public.activity_logs (
  61. id serial4 NOT NULL,
  62. ip_address text NULL,
  63. user_id int4 NULL,
  64. search_query text NULL,
  65. "timestamp" timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  66. CONSTRAINT activity_logs_pkey PRIMARY KEY (id),
  67. CONSTRAINT activity_logs_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.admin_users(id) ON DELETE SET NULL
  68. );
  69. -- public.dns_records definition
  70. -- Drop table
  71. -- DROP TABLE public.dns_records;
  72. CREATE TABLE public.dns_records (
  73. id serial4 NOT NULL,
  74. zone_id int4 NULL,
  75. hostname text NOT NULL,
  76. record_type text NULL,
  77. value text NULL,
  78. last_seen timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  79. CONSTRAINT dns_records_pkey PRIMARY KEY (id),
  80. CONSTRAINT dns_records_unique_node UNIQUE (zone_id, hostname, record_type, value),
  81. CONSTRAINT dns_records_zone_id_fkey FOREIGN KEY (zone_id) REFERENCES public.zones(id) ON DELETE CASCADE
  82. );
  83. CREATE INDEX idx_dns_hostname_trgm ON public.dns_records USING gin (hostname gin_trgm_ops);
  84. -- public.sponsored_links definition
  85. -- Drop table
  86. -- DROP TABLE public.sponsored_links;
  87. CREATE TABLE public.sponsored_links (
  88. id serial4 NOT NULL,
  89. title text NOT NULL,
  90. url text NOT NULL,
  91. description text NULL,
  92. keywords text NULL,
  93. is_active bool DEFAULT true NULL,
  94. user_id int4 NULL,
  95. CONSTRAINT sponsored_links_pkey PRIMARY KEY (id),
  96. CONSTRAINT sponsored_links_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.admin_users(id) ON DELETE CASCADE
  97. );
  98. -- public.web_health definition
  99. -- Drop table
  100. -- DROP TABLE public.web_health;
  101. CREATE TABLE public.web_health (
  102. id serial4 NOT NULL,
  103. dns_record_id int4 NULL,
  104. url text NULL,
  105. status_code int4 NULL,
  106. page_title text NULL,
  107. meta_description text NULL,
  108. h1_content text NULL,
  109. server_header text NULL,
  110. content_length int4 NULL,
  111. response_time_ms float8 NULL,
  112. body_preview text NULL,
  113. is_up bool NULL,
  114. last_check timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  115. keywords text NULL,
  116. clicks int4 DEFAULT 0 NULL,
  117. created_at timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  118. last_crawled timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  119. category varchar(50) DEFAULT 'Άγνωστο'::character varying NULL,
  120. ai_summary text NULL,
  121. activity_status varchar(20) NULL,
  122. pagerank_score float8 DEFAULT 1.0 NULL,
  123. full_content text NULL,
  124. authority_weight float8 DEFAULT 1.0 NULL,
  125. CONSTRAINT web_health_pkey PRIMARY KEY (id),
  126. CONSTRAINT web_health_url_key UNIQUE (url),
  127. CONSTRAINT web_health_dns_record_id_fkey FOREIGN KEY (dns_record_id) REFERENCES public.dns_records(id) ON DELETE CASCADE
  128. );
  129. CREATE INDEX idx_full_content_fts ON public.web_health USING gin (to_tsvector('greek'::regconfig, full_content));
  130. CREATE INDEX idx_wh_content_trgm ON public.web_health USING gin (full_content gin_trgm_ops);
  131. CREATE INDEX idx_wh_summary_trgm ON public.web_health USING gin (ai_summary gin_trgm_ops);
  132. CREATE INDEX idx_wh_title_trgm ON public.web_health USING gin (page_title gin_trgm_ops);
  133. -- public.web_links definition
  134. -- Drop table
  135. -- DROP TABLE public.web_links;
  136. CREATE TABLE public.web_links (
  137. id serial4 NOT NULL,
  138. dns_record_id int4 NULL,
  139. source_url text NOT NULL,
  140. target_url text NOT NULL,
  141. link_text text NULL,
  142. discovered_at timestamp DEFAULT CURRENT_TIMESTAMP NULL,
  143. CONSTRAINT web_links_pkey PRIMARY KEY (id),
  144. CONSTRAINT web_links_unique UNIQUE (source_url, target_url),
  145. CONSTRAINT web_links_dns_record_id_fkey FOREIGN KEY (dns_record_id) REFERENCES public.dns_records(id) ON DELETE CASCADE
  146. );
  147. CREATE INDEX idx_target_url ON public.web_links USING btree (target_url);