CJVT updates August and September 2026

This commit is contained in:
Luka Romih
2026-10-01 00:49:26 +02:00
parent fd02e25719
commit 83f73aeb58
135 changed files with 6146 additions and 1970 deletions
+1
View File
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM postgres:13-alpine AS base
FROM base AS builder
+1
View File
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
FROM postgres:13
ENV PG_MAJOR 13
+1 -1
View File
@@ -48,7 +48,7 @@ CREATE TABLE dictionary (
time_published TIMESTAMPTZ,
status dictionary_status NOT NULL DEFAULT 'closed',
count_entries INT NOT NULL DEFAULT 0, -- This one is updated manually and not through triggers.
count_comments INT,
count_comments INT, -- Indicator of own dictionaries: NULL means synced in from a linked/federated portal.
description VARCHAR,
entries_have_domain_labels BOOL NOT NULL DEFAULT FALSE,
entries_have_label BOOL NOT NULL DEFAULT FALSE,
+1 -2
View File
@@ -66,5 +66,4 @@ VALUES
('Zgodovina', 'History', '93/94', 'Zgodovina in umetnost', 'H 003', 'Humanities', '3611'),
('Zoologija', 'Zoology', '59', 'Zoologija', 'B 005', 'Natural and applied sciences', '3606'),
('Zootehnika in veterina', 'Zootechnics and veterinary medicine', '636', 'Zootehnika, živinoreja, vzreja', 'B 400', 'Health', '2841'),
('Živilstvo in kulinarika', 'Food industry and culinary', '641', 'Tehnologija hrane in pijač', 'T 430', 'Foodstuff', '6026'),
('Neopredeljeno', 'Undefined', '', '', '', '', '');
('Živilstvo in kulinarika', 'Food industry and culinary', '641', 'Tehnologija hrane in pijač', 'T 430', 'Foodstuff', '6026');
+1 -1
View File
@@ -87,7 +87,7 @@ CREATE TABLE process (
report VARCHAR
);
CREATE TYPE import_file_format AS ENUM ('xml', 'csv', 'tsv');
CREATE TYPE import_file_format AS ENUM ('xml', 'csv', 'tsv', 'json_term_candidates');
CREATE TYPE import_file_status AS ENUM ('in progress', 'error', 'done');
@@ -31,21 +31,6 @@ DECLARE
_secondary_domain_id domain_secondary.id%type;
BEGIN
-- Check uniqueness of names within own dictionaries.
IF EXISTS (
SELECT 1
FROM dictionary
WHERE
count_comments IS NOT NULL AND -- Indicator of own dictionaries.
(
name_sl = _name_sl OR
name_sl_short = _name_sl_short OR
name_en = _name_en
)
) THEN
RAISE EXCEPTION 'One of dictionary names not unique among own dictionaries.';
END IF;
-- Create new dictionary.
INSERT INTO dictionary (
name_sl,
@@ -0,0 +1,5 @@
-- Client-supplied IANA time zone (e.g. 'Europe/Ljubljana'), captured when the
-- export is started, used to render dates embedded in the exported file
-- content and the download filename in the requesting browser's local time
-- instead of the server's.
ALTER TABLE dictionary_export ADD COLUMN time_zone TEXT;
+18
View File
@@ -0,0 +1,18 @@
-- Adds support for federated/SSO login (OIDC) alongside local username+password accounts. Only
-- one external identity provider is modeled today: the University of Ljubljana (backed by
-- Microsoft Entra ID in production; a throwaway local Authentik instance stands in for it in dev
-- - see dev/authentik/). The auth_provider enum intentionally has just these two values.
CREATE TYPE auth_provider AS ENUM ('local', 'uni_lj');
-- SSO-only users are authenticated entirely by the external IdP and never set a local password.
ALTER TABLE "user" ALTER COLUMN bcrypt_hash DROP NOT NULL;
CREATE TABLE user_external_identity (
auth_provider auth_provider NOT NULL,
subject VARCHAR NOT NULL,
user_id INT NOT NULL REFERENCES "user",
time_linked TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (auth_provider, subject),
UNIQUE (user_id, auth_provider)
);
@@ -0,0 +1,26 @@
-- Companion DDL for postgres/init/023_external_identity.sql, for databases that already exist
-- (dev/staging/prod) and therefore never re-run postgres/init/*.sql. Run manually once per
-- environment, e.g.:
-- docker compose exec postgres psql -U postgres -d term_portal -f /path/to/this/file.sql
BEGIN;
CREATE TYPE auth_provider AS ENUM ('local', 'uni_lj');
ALTER TABLE "user" ALTER COLUMN bcrypt_hash DROP NOT NULL;
CREATE TABLE user_external_identity (
auth_provider auth_provider NOT NULL,
subject VARCHAR NOT NULL,
user_id INT NOT NULL REFERENCES "user",
time_linked TIMESTAMPTZ NOT NULL DEFAULT NOW(),
PRIMARY KEY (auth_provider, subject),
UNIQUE (user_id, auth_provider)
);
-- postgres/init/500_init_user.sql's blanket GRANT ALL ... TO express only runs once, at fresh-DB
-- provisioning time (before this table ever existed there) - it does not retroactively apply to
-- tables created later against an already-provisioned DB, so this table needs its own grant here.
GRANT ALL PRIVILEGES ON TABLE user_external_identity TO express;
COMMIT;
@@ -0,0 +1,56 @@
-- Script to remove the "Neopredeljeno" (Undefined) catch-all row from domain_primary.
-- Run manually against each environment's Postgres (dev/staging/prod) - the
-- postgres/init/*.sql seed scripts only run once, on first container init, so this
-- change does not otherwise propagate to already-initialized databases.
--
-- Safe to re-run: if the row is already gone, it's a no-op. If any dictionary or
-- consultancy_entry still references it, the delete is aborted (nothing is changed)
-- and the offending rows are listed below for manual reassignment.
-- Informational: list anything currently pointing at "Neopredeljeno", if it still exists.
SELECT 'dictionary' AS table_name, d.id, d.name_sl AS label, d.status::text AS status
FROM dictionary d
JOIN domain_primary dp ON dp.id = d.domain_primary_id
WHERE dp.name_sl = 'Neopredeljeno'
UNION ALL
SELECT 'consultancy_entry.domain_primary_id', ce.id, ce.title, ce.status::text
FROM consultancy_entry ce
JOIN domain_primary dp ON dp.id = ce.domain_primary_id
WHERE dp.name_sl = 'Neopredeljeno'
UNION ALL
SELECT 'consultancy_entry.domain_primary_id_initial', ce.id, ce.title, ce.status::text
FROM consultancy_entry ce
JOIN domain_primary dp ON dp.id = ce.domain_primary_id_initial
WHERE dp.name_sl = 'Neopredeljeno';
BEGIN;
DO $$
DECLARE
target_id smallint;
dict_count integer;
cons_count integer;
cons_initial_count integer;
BEGIN
SELECT id INTO target_id FROM domain_primary WHERE name_sl = 'Neopredeljeno';
IF target_id IS NULL THEN
RAISE NOTICE 'Row "Neopredeljeno" not found in domain_primary - nothing to do.';
RETURN;
END IF;
SELECT count(*) INTO dict_count FROM dictionary WHERE domain_primary_id = target_id;
SELECT count(*) INTO cons_count FROM consultancy_entry WHERE domain_primary_id = target_id;
SELECT count(*) INTO cons_initial_count FROM consultancy_entry WHERE domain_primary_id_initial = target_id;
IF dict_count > 0 OR cons_count > 0 OR cons_initial_count > 0 THEN
RAISE EXCEPTION
'Cannot remove "Neopredeljeno" (id=%): still referenced by % dictionary row(s), % consultancy_entry.domain_primary_id row(s), % consultancy_entry.domain_primary_id_initial row(s). Reassign these manually (see the SELECT above), then re-run this script.',
target_id, dict_count, cons_count, cons_initial_count;
END IF;
DELETE FROM domain_primary WHERE id = target_id;
RAISE NOTICE 'Removed domain_primary id=% ("Neopredeljeno").', target_id;
END $$;
COMMIT;