Actualización del 2025-08-16 a las 13:12:01
This commit is contained in:
parent
b44096b07c
commit
b26e9ad87f
13 changed files with 710 additions and 222 deletions
24
init-db/01.schema.sql
Normal file
24
init-db/01.schema.sql
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
CREATE TABLE IF NOT EXISTS continentes (id SERIAL PRIMARY KEY, nombre VARCHAR(50) NOT NULL UNIQUE);
|
||||
CREATE TABLE IF NOT EXISTS categorias (id SERIAL PRIMARY KEY, nombre VARCHAR(100) NOT NULL UNIQUE);
|
||||
CREATE TABLE IF NOT EXISTS paises (id SERIAL PRIMARY KEY, nombre VARCHAR(100) NOT NULL UNIQUE, continente_id INTEGER REFERENCES continentes(id) ON DELETE SET NULL);
|
||||
CREATE TABLE IF NOT EXISTS feeds (id SERIAL PRIMARY KEY, nombre VARCHAR(255), descripcion TEXT, url TEXT NOT NULL UNIQUE, categoria_id INTEGER REFERENCES categorias(id) ON DELETE SET NULL, pais_id INTEGER REFERENCES paises(id) ON DELETE SET NULL, idioma CHAR(2), activo BOOLEAN DEFAULT TRUE, fallos INTEGER DEFAULT 0, last_etag TEXT, last_modified TEXT);
|
||||
CREATE TABLE IF NOT EXISTS fuentes_url (id SERIAL PRIMARY KEY, nombre VARCHAR(255) NOT NULL, url TEXT NOT NULL UNIQUE, categoria_id INTEGER REFERENCES categorias(id) ON DELETE SET NULL, pais_id INTEGER REFERENCES paises(id) ON DELETE SET NULL, idioma CHAR(2) DEFAULT 'es');
|
||||
CREATE TABLE IF NOT EXISTS noticias (id VARCHAR(32) PRIMARY KEY, titulo TEXT, resumen TEXT, url TEXT NOT NULL UNIQUE, fecha TIMESTAMP, imagen_url TEXT, fuente_nombre VARCHAR(255), categoria_id INTEGER REFERENCES categorias(id) ON DELETE SET NULL, pais_id INTEGER REFERENCES paises(id) ON DELETE SET NULL, tsv tsvector);
|
||||
|
||||
ALTER TABLE noticias ADD COLUMN IF NOT EXISTS tsv tsvector;
|
||||
|
||||
CREATE OR REPLACE FUNCTION noticias_tsv_trigger() RETURNS trigger AS $$
|
||||
BEGIN
|
||||
new.tsv := setweight(to_tsvector('spanish', coalesce(new.titulo,'')), 'A') ||
|
||||
setweight(to_tsvector('spanish', coalesce(new.resumen,'')), 'B');
|
||||
return new;
|
||||
END
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
DROP TRIGGER IF EXISTS tsvectorupdate ON noticias;
|
||||
|
||||
CREATE TRIGGER tsvectorupdate
|
||||
BEFORE INSERT OR UPDATE ON noticias
|
||||
FOR EACH ROW EXECUTE PROCEDURE noticias_tsv_trigger();
|
||||
|
||||
CREATE INDEX IF NOT EXISTS noticias_tsv_idx ON noticias USING gin(tsv);
|
||||
Loading…
Add table
Add a link
Reference in a new issue