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
@@ -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;