From def9aa429383a1530acceec3969c2589ab4add64 Mon Sep 17 00:00:00 2001 From: jr-rk <95219754+jr-rk@users.noreply.github.com> Date: Tue, 11 Aug 2026 15:58:40 +0200 Subject: [PATCH 1/5] fix(db): drop hardcoded `public.` schema prefix from CLARIN migrations The V7.2 Lindat/Clarin and V7.6 Preview migrations qualified their `ALTER TABLE ... OWNER TO dspace` statements with `public.`, so instances whose DSpace tables live in a non-public schema could not run them. Remove the qualifier (17 statements across the two files) so each resolves against the connection's search_path. The unrelated bitstore.xml storage-bean swap from the source commit is omitted -- dtq-dev already uses SyncBitstreamStorageServiceImpl. Port of dataquest-dev/dspace-customers#903 (item 5). Source: customer/vsb-tuo e2fb08358e. Co-Authored-By: Claude Fable 5 --- ...07.28__Upgrade_to_Lindat_Clarin_schema.sql | 28 +++++++++---------- .../V7.6_2024.08.05__Added_Preview_Tables.sql | 6 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql index d056e15b947d..319db02003de 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql @@ -31,7 +31,7 @@ CREATE TABLE license_definition ( required_info varchar(256) ); -ALTER TABLE public.license_definition OWNER TO dspace; +ALTER TABLE license_definition OWNER TO dspace; -- -- Name: license_definition_license_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -44,7 +44,7 @@ CREATE SEQUENCE license_definition_license_id_seq NO MINVALUE CACHE 1; -ALTER TABLE public.license_definition_license_id_seq OWNER TO dspace; +ALTER TABLE license_definition_license_id_seq OWNER TO dspace; -- -- Name: license_definition_license_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -65,7 +65,7 @@ CREATE TABLE license_label ( ); -ALTER TABLE public.license_label OWNER TO dspace; +ALTER TABLE license_label OWNER TO dspace; -- -- Name: license_label_extended_mapping; Type: TABLE; Schema: public; Owner: dspace; Tablespace: @@ -77,7 +77,7 @@ CREATE TABLE license_label_extended_mapping ( label_id integer ); -ALTER TABLE public.license_label_extended_mapping OWNER TO dspace; +ALTER TABLE license_label_extended_mapping OWNER TO dspace; -- -- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -91,7 +91,7 @@ CREATE SEQUENCE license_label_extended_mapping_mapping_id_seq CACHE 1; -ALTER TABLE public.license_label_extended_mapping_mapping_id_seq OWNER TO dspace; +ALTER TABLE license_label_extended_mapping_mapping_id_seq OWNER TO dspace; -- -- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -118,7 +118,7 @@ CREATE SEQUENCE license_label_label_id_seq CACHE 1; -ALTER TABLE public.license_label_label_id_seq OWNER TO dspace; +ALTER TABLE license_label_label_id_seq OWNER TO dspace; -- -- Name: license_label_label_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -144,7 +144,7 @@ CREATE TABLE license_resource_mapping ( ); -ALTER TABLE public.license_resource_mapping OWNER TO dspace; +ALTER TABLE license_resource_mapping OWNER TO dspace; -- -- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -158,7 +158,7 @@ CREATE SEQUENCE license_resource_mapping_mapping_id_seq CACHE 1; -ALTER TABLE public.license_resource_mapping_mapping_id_seq OWNER TO dspace; +ALTER TABLE license_resource_mapping_mapping_id_seq OWNER TO dspace; -- -- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -186,7 +186,7 @@ CREATE TABLE license_resource_user_allowance ( token varchar(256) ); -ALTER TABLE public.license_resource_user_allowance OWNER TO dspace; +ALTER TABLE license_resource_user_allowance OWNER TO dspace; -- -- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -199,7 +199,7 @@ CREATE SEQUENCE license_resource_user_allowance_transaction_id_seq NO MINVALUE CACHE 1; -ALTER TABLE public.license_resource_user_allowance_transaction_id_seq OWNER TO dspace; +ALTER TABLE license_resource_user_allowance_transaction_id_seq OWNER TO dspace; -- -- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -224,7 +224,7 @@ CREATE TABLE user_registration ( confirmation boolean DEFAULT true ); -ALTER TABLE public.user_registration OWNER TO dspace; +ALTER TABLE user_registration OWNER TO dspace; CREATE SEQUENCE user_registration_user_registration_id_seq START WITH 1 @@ -233,7 +233,7 @@ CREATE SEQUENCE user_registration_user_registration_id_seq NO MINVALUE CACHE 1; -ALTER TABLE public.user_registration_user_registration_id_seq OWNER TO dspace; +ALTER TABLE user_registration_user_registration_id_seq OWNER TO dspace; -- -- Name: user_registration_user_registration_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -254,7 +254,7 @@ CREATE TABLE user_metadata ( ); -ALTER TABLE public.user_metadata OWNER TO dspace; +ALTER TABLE user_metadata OWNER TO dspace; -- -- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -268,7 +268,7 @@ CREATE SEQUENCE user_metadata_user_metadata_id_seq CACHE 1; -ALTER TABLE public.user_metadata_user_metadata_id_seq OWNER TO dspace; +ALTER TABLE user_metadata_user_metadata_id_seq OWNER TO dspace; -- -- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql index 57919fbfa8e6..74b677d73fd5 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql @@ -19,7 +19,7 @@ CREATE TABLE previewcontent ( size varchar(256) ); -ALTER TABLE public.previewcontent OWNER TO dspace; +ALTER TABLE previewcontent OWNER TO dspace; -- -- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -32,7 +32,7 @@ CREATE SEQUENCE previewcontent_previewcontent_id_seq NO MINVALUE CACHE 1; -ALTER TABLE public.previewcontent_previewcontent_id_seq OWNER TO dspace; +ALTER TABLE previewcontent_previewcontent_id_seq OWNER TO dspace; -- -- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -64,7 +64,7 @@ CREATE TABLE preview2preview ( name varchar(2000) ); -ALTER TABLE public.preview2preview OWNER TO dspace; +ALTER TABLE preview2preview OWNER TO dspace; -- -- Name: preview2preview_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: From 63995e70583f01bb1041666872df994cf82c40cf Mon Sep 17 00:00:00 2001 From: jr-rk <95219754+jr-rk@users.noreply.github.com> Date: Fri, 11 Sep 2026 14:26:23 +0200 Subject: [PATCH 2/5] fix(db): reassign CLARIN table ownership without the `public.` prefix Revert the in-place edits to V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql and V7.6_2024.08.05__Added_Preview_Tables.sql -- both are already applied, so changing their content breaks their Flyway checksum and every existing install fails validation on the next startup. Add V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql instead, which restates the same `ALTER TABLE ... OWNER TO dspace` intent for the 17 CLARIN and preview objects, resolving each name through search_path via to_regclass() rather than a hardcoded `public.` qualifier. The reassignment is best-effort: it is skipped when the `dspace` role is absent, when the object is already owned by it, or when the statement lacks the required privileges (the target role needs CREATE on the object's schema). A tenant-owned schema therefore keeps its current owner instead of failing the migration. Verified against PostgreSQL 15 for: non-public schema with and without the schema grant, repeated runs, a database with no CLARIN tables, a classic public-schema install, and a cluster with no `dspace` role. Only the search_path schema is touched -- a same-named table in `public` is left alone. Co-Authored-By: Claude Opus 5 --- ...07.28__Upgrade_to_Lindat_Clarin_schema.sql | 28 +++---- .../V7.6_2024.08.05__Added_Preview_Tables.sql | 6 +- ...1__Clarin_tables_owner_schema_agnostic.sql | 73 +++++++++++++++++++ 3 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql index 319db02003de..d056e15b947d 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql @@ -31,7 +31,7 @@ CREATE TABLE license_definition ( required_info varchar(256) ); -ALTER TABLE license_definition OWNER TO dspace; +ALTER TABLE public.license_definition OWNER TO dspace; -- -- Name: license_definition_license_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -44,7 +44,7 @@ CREATE SEQUENCE license_definition_license_id_seq NO MINVALUE CACHE 1; -ALTER TABLE license_definition_license_id_seq OWNER TO dspace; +ALTER TABLE public.license_definition_license_id_seq OWNER TO dspace; -- -- Name: license_definition_license_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -65,7 +65,7 @@ CREATE TABLE license_label ( ); -ALTER TABLE license_label OWNER TO dspace; +ALTER TABLE public.license_label OWNER TO dspace; -- -- Name: license_label_extended_mapping; Type: TABLE; Schema: public; Owner: dspace; Tablespace: @@ -77,7 +77,7 @@ CREATE TABLE license_label_extended_mapping ( label_id integer ); -ALTER TABLE license_label_extended_mapping OWNER TO dspace; +ALTER TABLE public.license_label_extended_mapping OWNER TO dspace; -- -- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -91,7 +91,7 @@ CREATE SEQUENCE license_label_extended_mapping_mapping_id_seq CACHE 1; -ALTER TABLE license_label_extended_mapping_mapping_id_seq OWNER TO dspace; +ALTER TABLE public.license_label_extended_mapping_mapping_id_seq OWNER TO dspace; -- -- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -118,7 +118,7 @@ CREATE SEQUENCE license_label_label_id_seq CACHE 1; -ALTER TABLE license_label_label_id_seq OWNER TO dspace; +ALTER TABLE public.license_label_label_id_seq OWNER TO dspace; -- -- Name: license_label_label_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -144,7 +144,7 @@ CREATE TABLE license_resource_mapping ( ); -ALTER TABLE license_resource_mapping OWNER TO dspace; +ALTER TABLE public.license_resource_mapping OWNER TO dspace; -- -- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -158,7 +158,7 @@ CREATE SEQUENCE license_resource_mapping_mapping_id_seq CACHE 1; -ALTER TABLE license_resource_mapping_mapping_id_seq OWNER TO dspace; +ALTER TABLE public.license_resource_mapping_mapping_id_seq OWNER TO dspace; -- -- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -186,7 +186,7 @@ CREATE TABLE license_resource_user_allowance ( token varchar(256) ); -ALTER TABLE license_resource_user_allowance OWNER TO dspace; +ALTER TABLE public.license_resource_user_allowance OWNER TO dspace; -- -- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -199,7 +199,7 @@ CREATE SEQUENCE license_resource_user_allowance_transaction_id_seq NO MINVALUE CACHE 1; -ALTER TABLE license_resource_user_allowance_transaction_id_seq OWNER TO dspace; +ALTER TABLE public.license_resource_user_allowance_transaction_id_seq OWNER TO dspace; -- -- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -224,7 +224,7 @@ CREATE TABLE user_registration ( confirmation boolean DEFAULT true ); -ALTER TABLE user_registration OWNER TO dspace; +ALTER TABLE public.user_registration OWNER TO dspace; CREATE SEQUENCE user_registration_user_registration_id_seq START WITH 1 @@ -233,7 +233,7 @@ CREATE SEQUENCE user_registration_user_registration_id_seq NO MINVALUE CACHE 1; -ALTER TABLE user_registration_user_registration_id_seq OWNER TO dspace; +ALTER TABLE public.user_registration_user_registration_id_seq OWNER TO dspace; -- -- Name: user_registration_user_registration_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -254,7 +254,7 @@ CREATE TABLE user_metadata ( ); -ALTER TABLE user_metadata OWNER TO dspace; +ALTER TABLE public.user_metadata OWNER TO dspace; -- -- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -268,7 +268,7 @@ CREATE SEQUENCE user_metadata_user_metadata_id_seq CACHE 1; -ALTER TABLE user_metadata_user_metadata_id_seq OWNER TO dspace; +ALTER TABLE public.user_metadata_user_metadata_id_seq OWNER TO dspace; -- -- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql index 74b677d73fd5..57919fbfa8e6 100644 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2024.08.05__Added_Preview_Tables.sql @@ -19,7 +19,7 @@ CREATE TABLE previewcontent ( size varchar(256) ); -ALTER TABLE previewcontent OWNER TO dspace; +ALTER TABLE public.previewcontent OWNER TO dspace; -- -- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace @@ -32,7 +32,7 @@ CREATE SEQUENCE previewcontent_previewcontent_id_seq NO MINVALUE CACHE 1; -ALTER TABLE previewcontent_previewcontent_id_seq OWNER TO dspace; +ALTER TABLE public.previewcontent_previewcontent_id_seq OWNER TO dspace; -- -- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace @@ -64,7 +64,7 @@ CREATE TABLE preview2preview ( name varchar(2000) ); -ALTER TABLE preview2preview OWNER TO dspace; +ALTER TABLE public.preview2preview OWNER TO dspace; -- -- Name: preview2preview_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql new file mode 100644 index 000000000000..3037ee84c2b1 --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql @@ -0,0 +1,73 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +----------------------------------------------------------------------------------- +-- Re-apply the CLARIN / preview object ownership without the hardcoded `public.` +-- schema qualifier. +-- +-- V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql and +-- V7.6_2024.08.05__Added_Preview_Tables.sql issue `ALTER TABLE public. OWNER TO +-- dspace`, binding the statement to the `public` schema instead of the connection's +-- search_path. Those files are already applied, so editing them would break their +-- Flyway checksum; this migration restates the same intent schema-agnostically. +-- +-- Ownership is best-effort: the statement needs the current role to own the object and +-- to be a member of `dspace`, and `dspace` to hold CREATE on the object's schema. Any +-- install that does not satisfy that (different role name, tenant-owned schema) is left +-- untouched with a notice rather than failing the migration. +----------------------------------------------------------------------------------- +DO $$ +DECLARE + target_owner CONSTANT text := 'dspace'; + objects CONSTANT text[] := ARRAY[ + 'license_definition', + 'license_definition_license_id_seq', + 'license_label', + 'license_label_label_id_seq', + 'license_label_extended_mapping', + 'license_label_extended_mapping_mapping_id_seq', + 'license_resource_mapping', + 'license_resource_mapping_mapping_id_seq', + 'license_resource_user_allowance', + 'license_resource_user_allowance_transaction_id_seq', + 'user_registration', + 'user_registration_user_registration_id_seq', + 'user_metadata', + 'user_metadata_user_metadata_id_seq', + 'previewcontent', + 'previewcontent_previewcontent_id_seq', + 'preview2preview' + ]; + object_name text; + object_oid oid; +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = target_owner) THEN + RAISE NOTICE 'Role % does not exist, leaving object ownership unchanged.', target_owner; + RETURN; + END IF; + + FOREACH object_name IN ARRAY objects LOOP + -- Unqualified to_regclass() resolves against search_path, so the object is found + -- in whichever schema this install actually uses. + object_oid := to_regclass(object_name); + CONTINUE WHEN object_oid IS NULL; + + CONTINUE WHEN EXISTS ( + SELECT 1 FROM pg_class c + JOIN pg_roles r ON r.oid = c.relowner + WHERE c.oid = object_oid AND r.rolname = target_owner + ); + + BEGIN + EXECUTE format('ALTER TABLE %s OWNER TO %I', object_oid::regclass, target_owner); + EXCEPTION WHEN insufficient_privilege THEN + RAISE NOTICE 'Cannot reassign % to %, leaving its current owner in place: %', + object_oid::regclass, target_owner, SQLERRM; + END; + END LOOP; +END $$; From 99896d62f9ee65a2f730876a928db9c67edf69c5 Mon Sep 17 00:00:00 2001 From: jr-rk <95219754+jr-rk@users.noreply.github.com> Date: Mon, 14 Sep 2026 12:17:49 +0200 Subject: [PATCH 3/5] Revert "fix(db): reassign CLARIN table ownership without the `public.` prefix" This reverts commit 63995e7058, restoring the branch to its base content. The forward migration reassigned object ownership at a new point in time, which the task never asked for: `public.` appears in V7.2 / V7.6 only inside `ALTER TABLE public. OWNER TO dspace`, so restating those statements later performs ownership churn on installs that are already correct -- and on a tenant-owned schema it would move objects away from the tenant role. Every other statement in both migrations is unqualified and already resolves through the schema configured by `db.schema` (dspace.cfg), so nothing else needs a forward fix. Removing the hardcoded prefix requires editing V7.2 / V7.6 themselves, which is the open question for the reviewer. Co-Authored-By: Claude Opus 5 --- ...1__Clarin_tables_owner_schema_agnostic.sql | 73 ------------------- 1 file changed, 73 deletions(-) delete mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql deleted file mode 100644 index 3037ee84c2b1..000000000000 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.11__Clarin_tables_owner_schema_agnostic.sql +++ /dev/null @@ -1,73 +0,0 @@ --- --- The contents of this file are subject to the license and copyright --- detailed in the LICENSE and NOTICE files at the root of the source --- tree and available online at --- --- http://www.dspace.org/license/ --- - ------------------------------------------------------------------------------------ --- Re-apply the CLARIN / preview object ownership without the hardcoded `public.` --- schema qualifier. --- --- V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql and --- V7.6_2024.08.05__Added_Preview_Tables.sql issue `ALTER TABLE public. OWNER TO --- dspace`, binding the statement to the `public` schema instead of the connection's --- search_path. Those files are already applied, so editing them would break their --- Flyway checksum; this migration restates the same intent schema-agnostically. --- --- Ownership is best-effort: the statement needs the current role to own the object and --- to be a member of `dspace`, and `dspace` to hold CREATE on the object's schema. Any --- install that does not satisfy that (different role name, tenant-owned schema) is left --- untouched with a notice rather than failing the migration. ------------------------------------------------------------------------------------ -DO $$ -DECLARE - target_owner CONSTANT text := 'dspace'; - objects CONSTANT text[] := ARRAY[ - 'license_definition', - 'license_definition_license_id_seq', - 'license_label', - 'license_label_label_id_seq', - 'license_label_extended_mapping', - 'license_label_extended_mapping_mapping_id_seq', - 'license_resource_mapping', - 'license_resource_mapping_mapping_id_seq', - 'license_resource_user_allowance', - 'license_resource_user_allowance_transaction_id_seq', - 'user_registration', - 'user_registration_user_registration_id_seq', - 'user_metadata', - 'user_metadata_user_metadata_id_seq', - 'previewcontent', - 'previewcontent_previewcontent_id_seq', - 'preview2preview' - ]; - object_name text; - object_oid oid; -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = target_owner) THEN - RAISE NOTICE 'Role % does not exist, leaving object ownership unchanged.', target_owner; - RETURN; - END IF; - - FOREACH object_name IN ARRAY objects LOOP - -- Unqualified to_regclass() resolves against search_path, so the object is found - -- in whichever schema this install actually uses. - object_oid := to_regclass(object_name); - CONTINUE WHEN object_oid IS NULL; - - CONTINUE WHEN EXISTS ( - SELECT 1 FROM pg_class c - JOIN pg_roles r ON r.oid = c.relowner - WHERE c.oid = object_oid AND r.rolname = target_owner - ); - - BEGIN - EXECUTE format('ALTER TABLE %s OWNER TO %I', object_oid::regclass, target_owner); - EXCEPTION WHEN insufficient_privilege THEN - RAISE NOTICE 'Cannot reassign % to %, leaving its current owner in place: %', - object_oid::regclass, target_owner, SQLERRM; - END; - END LOOP; -END $$; From 844b17f01bb64c8c4c5200fa9c688ab3221cb54c Mon Sep 17 00:00:00 2001 From: jr-rk <95219754+jr-rk@users.noreply.github.com> Date: Mon, 14 Sep 2026 13:16:00 +0200 Subject: [PATCH 4/5] fix(db): add schema-agnostic copy of the CLARIN migrations V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql and V7.6_2024.08.05__Added_Preview_Tables.sql qualify their `ALTER TABLE ... OWNER TO dspace` statements with `public.`, so they ignore the schema configured in `db.schema`. Both are already applied and editing them would break their Flyway checksum, so this adds V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql: the same DDL with every object name unqualified, resolving through the connection's search_path. The copy is idempotent, because it also runs on the installs that already applied the originals: `CREATE ... IF NOT EXISTS` for tables, sequences and the unique index, `ADD COLUMN IF NOT EXISTS` for the eperson and handle columns, a catalog lookup before each constraint, and the `pg_catalog.setval()` baselines only while the owning table is still empty, so a live sequence is never rewound. Ownership is skipped when the role is absent, already correct, or not reassignable. Verified against PostgreSQL 15: - install that already ran both originals: exit 0, catalog snapshot unchanged (133 entries), seeded sequence values preserved; - fresh non-`public` schema: 23 relations and 26 constraints created in the configured schema, nothing in `public`, sequence baselines 991137 / 19 / 1382 / 241 / 68 as in the originals; - structural comparison of originals-in-`public` against this script in a tenant schema: 101 catalog entries each, identical; - rerun: no further changes. Co-Authored-By: Claude Opus 5 --- ...4__Clarin_schema_without_public_prefix.sql | 310 ++++++++++++++++++ 1 file changed, 310 insertions(+) create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql new file mode 100644 index 000000000000..b134fd59d703 --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql @@ -0,0 +1,310 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +----------------------------------------------------------------------------------- +-- Schema-agnostic restatement of the CLARIN schema created by +-- V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql +-- V7.6_2024.08.05__Added_Preview_Tables.sql +-- +-- Those two migrations qualify their `ALTER TABLE ... OWNER TO dspace` statements with +-- `public.`, so they ignore the schema configured in `db.schema` (dspace.cfg). They are +-- already applied and cannot be edited without breaking their Flyway checksum, so this +-- migration carries the same DDL with every object name unqualified -- each one resolves +-- through the connection's search_path instead. +-- +-- Everything here is idempotent: an install that already ran the originals gets no +-- changes at all. Sequence baselines are applied only while the owning table is still +-- empty, and ownership is skipped whenever the statement would fail. +----------------------------------------------------------------------------------- + +-- HANDLE TABLE +ALTER TABLE handle ADD COLUMN IF NOT EXISTS url varchar; +ALTER TABLE handle ADD COLUMN IF NOT EXISTS dead BOOL; +ALTER TABLE handle ADD COLUMN IF NOT EXISTS dead_since TIMESTAMP WITH TIME ZONE; + +-- MetadataField table +-- Because of metashareSchema +ALTER TABLE metadatafieldregistry ALTER COLUMN element TYPE character varying(128); + +ALTER TABLE eperson ALTER COLUMN netid TYPE character varying(256); +ALTER TABLE eperson ALTER COLUMN email TYPE character varying(256); +ALTER TABLE eperson ADD COLUMN IF NOT EXISTS welcome_info varchar(30); +ALTER TABLE eperson ADD COLUMN IF NOT EXISTS can_edit_submission_metadata BOOL; + +-- LICENSES +CREATE TABLE IF NOT EXISTS license_definition ( + license_id integer NOT NULL, + name varchar(256), + definition varchar(256), + user_registration_id integer, + label_id integer, + created_on timestamp, + confirmation integer DEFAULT 0, + required_info varchar(256) +); + +CREATE TABLE IF NOT EXISTS license_label ( + label_id integer NOT NULL, + label varchar(5), + title varchar(180), + icon bytea, + is_extended boolean DEFAULT false +); + +CREATE TABLE IF NOT EXISTS license_label_extended_mapping ( + mapping_id integer NOT NULL, + license_id integer, + label_id integer +); + +CREATE TABLE IF NOT EXISTS license_resource_mapping ( + mapping_id integer NOT NULL, + bitstream_uuid uuid, + license_id integer +); + +CREATE TABLE IF NOT EXISTS license_resource_user_allowance ( + transaction_id integer NOT NULL, + user_registration_id integer, + mapping_id integer, + created_on timestamp, + token varchar(256) +); + +CREATE TABLE IF NOT EXISTS user_registration ( + user_registration_id integer NOT NULL, + eperson_id UUID, + email character varying(256), + organization character varying(256), + confirmation boolean DEFAULT true +); + +CREATE TABLE IF NOT EXISTS user_metadata ( + user_metadata_id integer NOT NULL, + user_registration_id integer, + metadata_key character varying(64), + metadata_value character varying(256), + transaction_id integer +); + +CREATE TABLE IF NOT EXISTS verification_token ( + verification_token_id integer NOT NULL, + eperson_netid varchar(256), + shib_headers varchar(2048), + token varchar(256), + email varchar(256) +); + +-- PREVIEW CONTENT +CREATE TABLE IF NOT EXISTS previewcontent ( + previewcontent_id integer NOT NULL, + bitstream_id uuid NOT NULL, + name varchar(2000), + content varchar(2000), + isDirectory boolean DEFAULT false, + size varchar(256) +); + +CREATE TABLE IF NOT EXISTS preview2preview ( + parent_id integer NOT NULL, + child_id integer NOT NULL, + name varchar(2000) +); + +-- SEQUENCES +CREATE SEQUENCE IF NOT EXISTS license_definition_license_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS license_label_label_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS license_label_extended_mapping_mapping_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS license_resource_mapping_mapping_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS license_resource_user_allowance_transaction_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS user_registration_user_registration_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS user_metadata_user_metadata_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS verification_token_verification_token_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +CREATE SEQUENCE IF NOT EXISTS previewcontent_previewcontent_id_seq + START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; + +ALTER SEQUENCE license_definition_license_id_seq OWNED BY license_definition.license_id; +ALTER SEQUENCE license_label_label_id_seq OWNED BY license_label.label_id; +ALTER SEQUENCE license_label_extended_mapping_mapping_id_seq OWNED BY license_label_extended_mapping.mapping_id; +ALTER SEQUENCE license_resource_mapping_mapping_id_seq OWNED BY license_resource_mapping.mapping_id; +ALTER SEQUENCE license_resource_user_allowance_transaction_id_seq OWNED BY license_resource_user_allowance.transaction_id; +ALTER SEQUENCE user_metadata_user_metadata_id_seq OWNED BY user_metadata.user_metadata_id; +ALTER SEQUENCE previewcontent_previewcontent_id_seq OWNED BY previewcontent.previewcontent_id; + +-- The original left this one commented out; it stays that way. +--ALTER SEQUENCE user_registration_user_registration_id_seq OWNED BY user_registration.eperson_id; + +-- COLUMN DEFAULTS +ALTER TABLE ONLY license_definition ALTER COLUMN license_id SET DEFAULT nextval('license_definition_license_id_seq'::regclass); +ALTER TABLE ONLY license_label ALTER COLUMN label_id SET DEFAULT nextval('license_label_label_id_seq'::regclass); +ALTER TABLE ONLY license_label_extended_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_label_extended_mapping_mapping_id_seq'::regclass); +ALTER TABLE ONLY license_resource_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_resource_mapping_mapping_id_seq'::regclass); +ALTER TABLE ONLY license_resource_user_allowance ALTER COLUMN transaction_id SET DEFAULT nextval('license_resource_user_allowance_transaction_id_seq'::regclass); +ALTER TABLE ONLY user_metadata ALTER COLUMN user_metadata_id SET DEFAULT nextval('user_metadata_user_metadata_id_seq'::regclass); +ALTER TABLE ONLY verification_token ALTER COLUMN verification_token_id SET DEFAULT nextval('verification_token_verification_token_id_seq'::regclass); + +-- The original left this one commented out; it stays that way. +--ALTER TABLE ONLY user_registration ALTER COLUMN eperson_id SET DEFAULT nextval('user_registration_user_registration_id_seq'::regclass); + +-- SEQUENCE BASELINES +-- The originals set these to the values carried over from the CLARIN 5 migration. Applying +-- them to a populated table would rewind a live sequence, so each one runs only while its +-- owning table is still empty. +DO $$ +DECLARE + baseline record; + table_has_rows boolean; +BEGIN + FOR baseline IN + SELECT * FROM (VALUES + ('license_label_extended_mapping_mapping_id_seq', 'license_label_extended_mapping', 991137), + ('license_label_label_id_seq', 'license_label', 19), + ('license_resource_mapping_mapping_id_seq', 'license_resource_mapping', 1382), + ('license_resource_user_allowance_transaction_id_seq', 'license_resource_user_allowance', 241), + ('user_metadata_user_metadata_id_seq', 'user_metadata', 68) + ) AS t(sequence_name, table_name, last_value) + LOOP + CONTINUE WHEN to_regclass(baseline.sequence_name) IS NULL; + CONTINUE WHEN to_regclass(baseline.table_name) IS NULL; + + EXECUTE format('SELECT EXISTS (SELECT 1 FROM %s)', to_regclass(baseline.table_name)) + INTO table_has_rows; + CONTINUE WHEN table_has_rows; + + PERFORM setval(to_regclass(baseline.sequence_name), baseline.last_value, true); + END LOOP; +END $$; + +-- CONSTRAINTS +DO $$ +DECLARE + c record; +BEGIN + FOR c IN + SELECT * FROM (VALUES + ('license_definition', 'license_definition_pkey', 'PRIMARY KEY (license_id)'), + ('license_label', 'license_label_pkey', 'PRIMARY KEY (label_id)'), + ('license_label_extended_mapping', 'license_label_extended_mapping_pkey', 'PRIMARY KEY (mapping_id)'), + ('license_resource_mapping', 'license_resource_mapping_pkey', 'PRIMARY KEY (mapping_id)'), + ('license_resource_user_allowance', 'license_resource_user_allowance_pkey', 'PRIMARY KEY (transaction_id)'), + ('user_registration', 'user_registration_pkey', 'PRIMARY KEY (user_registration_id)'), + ('user_metadata', 'user_metadata_pkey', 'PRIMARY KEY (user_metadata_id)'), + ('verification_token', 'verification_token_pkey', 'PRIMARY KEY (verification_token_id)'), + ('previewcontent', 'previewcontent_pkey', 'PRIMARY KEY (previewcontent_id)'), + ('preview2preview', 'preview2preview_pkey', 'PRIMARY KEY (parent_id, child_id)'), + ('license_label_extended_mapping', 'license_definition_license_label_extended_mapping_fk', + 'FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE'), + ('license_label_extended_mapping', 'license_label_license_label_extended_mapping_fk', + 'FOREIGN KEY (label_id) REFERENCES license_label(label_id) ON DELETE CASCADE'), + ('license_resource_mapping', 'license_definition_license_resource_mapping_fk', + 'FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE'), + ('license_resource_mapping', 'bitstream_license_resource_mapping_fk', + 'FOREIGN KEY (bitstream_uuid) REFERENCES bitstream(uuid) ON DELETE CASCADE'), + ('license_resource_user_allowance', 'license_resource_mapping_license_resource_user_allowance_fk', + 'FOREIGN KEY (mapping_id) REFERENCES license_resource_mapping(mapping_id) ON UPDATE CASCADE ON DELETE CASCADE'), + ('license_resource_user_allowance', 'user_registration_license_resource_user_allowance_fk', + 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), + ('license_definition', 'user_registration_license_definition_fk', + 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), + ('user_metadata', 'license_resource_user_allowance_user_metadata_fk', + 'FOREIGN KEY (transaction_id) REFERENCES license_resource_user_allowance(transaction_id) ON UPDATE CASCADE ON DELETE CASCADE'), + ('user_metadata', 'user_registration_user_metadata_fk', + 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), + ('previewcontent', 'previewcontent_bitstream_fk', + 'FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid) ON DELETE CASCADE'), + ('preview2preview', 'preview2preview_parent_fk', + 'FOREIGN KEY (parent_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE'), + ('preview2preview', 'preview2preview_child_fk', + 'FOREIGN KEY (child_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE') + ) AS t(table_name, constraint_name, definition) + LOOP + CONTINUE WHEN to_regclass(c.table_name) IS NULL; + CONTINUE WHEN EXISTS ( + SELECT 1 FROM pg_constraint + WHERE conname = c.constraint_name AND conrelid = to_regclass(c.table_name) + ); + + EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %I %s', + to_regclass(c.table_name), c.constraint_name, c.definition); + END LOOP; +END $$; + +-- The original left this one commented out; it stays that way. +--ALTER TABLE ONLY license_definition +-- ADD CONSTRAINT license_label_license_definition_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id); + +CREATE UNIQUE INDEX IF NOT EXISTS license_definition_license_id_key ON license_definition USING btree (name); + +-- OWNERSHIP +-- The statements this migration exists for. Unqualified, so they apply to the schema the +-- connection actually uses. Skipped when the role is missing, when the object already +-- belongs to it, or when the current role may not reassign it -- an install whose objects +-- belong to a tenant role keeps them. +DO $$ +DECLARE + target_owner CONSTANT text := 'dspace'; + objects CONSTANT text[] := ARRAY[ + 'license_definition', + 'license_definition_license_id_seq', + 'license_label', + 'license_label_label_id_seq', + 'license_label_extended_mapping', + 'license_label_extended_mapping_mapping_id_seq', + 'license_resource_mapping', + 'license_resource_mapping_mapping_id_seq', + 'license_resource_user_allowance', + 'license_resource_user_allowance_transaction_id_seq', + 'user_registration', + 'user_registration_user_registration_id_seq', + 'user_metadata', + 'user_metadata_user_metadata_id_seq', + 'previewcontent', + 'previewcontent_previewcontent_id_seq', + 'preview2preview' + ]; + object_name text; + object_oid oid; +BEGIN + IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = target_owner) THEN + RAISE NOTICE 'Role % does not exist, leaving object ownership unchanged.', target_owner; + RETURN; + END IF; + + FOREACH object_name IN ARRAY objects LOOP + object_oid := to_regclass(object_name); + CONTINUE WHEN object_oid IS NULL; + CONTINUE WHEN EXISTS ( + SELECT 1 FROM pg_class cls + JOIN pg_roles r ON r.oid = cls.relowner + WHERE cls.oid = object_oid AND r.rolname = target_owner + ); + + BEGIN + EXECUTE format('ALTER TABLE %s OWNER TO %I', object_oid::regclass, target_owner); + EXCEPTION WHEN insufficient_privilege THEN + RAISE NOTICE 'Cannot reassign % to %, leaving its current owner in place: %', + object_oid::regclass, target_owner, SQLERRM; + END; + END LOOP; +END $$; From 2c5959107f1b6b165f2a0dcc2651518273e861b5 Mon Sep 17 00:00:00 2001 From: jr-rk <95219754+jr-rk@users.noreply.github.com> Date: Mon, 14 Sep 2026 14:09:18 +0200 Subject: [PATCH 5/5] fix(db): duplicate CLARIN migrations without the `public.` schema prefix V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql and V7.6_2024.08.05__Added_Preview_Tables.sql qualify their `ALTER TABLE ... OWNER TO dspace` statements with `public.`, so those statements ignore the schema configured in `db.schema`. Both files are already applied and editing them would break their Flyway checksum, so each is duplicated under a new version instead: V7.6_2026.09.14__Upgrade_to_Lindat_Clarin_schema.sql (from V7.2, lines 34, 47, 68, 80, 94, 121, 147, 161, 189, 202, 227, 236, 257, 271) V7.6_2026.09.15__Added_Preview_Tables.sql (from V7.6_2024.08.05, lines 22, 35, 67) The copies are byte-identical to their sources apart from those 17 lines, where the `public.` qualifier is dropped so the statement resolves against the connection's search_path. Nothing else is changed. The two originals stay untouched, so no checksum moves. Co-Authored-By: Claude Opus 5 --- ...4__Clarin_schema_without_public_prefix.sql | 310 ----------- ...09.14__Upgrade_to_Lindat_Clarin_schema.sql | 490 ++++++++++++++++++ .../V7.6_2026.09.15__Added_Preview_Tables.sql | 88 ++++ 3 files changed, 578 insertions(+), 310 deletions(-) delete mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Upgrade_to_Lindat_Clarin_schema.sql create mode 100644 dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.15__Added_Preview_Tables.sql diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql deleted file mode 100644 index b134fd59d703..000000000000 --- a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Clarin_schema_without_public_prefix.sql +++ /dev/null @@ -1,310 +0,0 @@ --- --- The contents of this file are subject to the license and copyright --- detailed in the LICENSE and NOTICE files at the root of the source --- tree and available online at --- --- http://www.dspace.org/license/ --- - ------------------------------------------------------------------------------------ --- Schema-agnostic restatement of the CLARIN schema created by --- V7.2_2022.07.28__Upgrade_to_Lindat_Clarin_schema.sql --- V7.6_2024.08.05__Added_Preview_Tables.sql --- --- Those two migrations qualify their `ALTER TABLE ... OWNER TO dspace` statements with --- `public.`, so they ignore the schema configured in `db.schema` (dspace.cfg). They are --- already applied and cannot be edited without breaking their Flyway checksum, so this --- migration carries the same DDL with every object name unqualified -- each one resolves --- through the connection's search_path instead. --- --- Everything here is idempotent: an install that already ran the originals gets no --- changes at all. Sequence baselines are applied only while the owning table is still --- empty, and ownership is skipped whenever the statement would fail. ------------------------------------------------------------------------------------ - --- HANDLE TABLE -ALTER TABLE handle ADD COLUMN IF NOT EXISTS url varchar; -ALTER TABLE handle ADD COLUMN IF NOT EXISTS dead BOOL; -ALTER TABLE handle ADD COLUMN IF NOT EXISTS dead_since TIMESTAMP WITH TIME ZONE; - --- MetadataField table --- Because of metashareSchema -ALTER TABLE metadatafieldregistry ALTER COLUMN element TYPE character varying(128); - -ALTER TABLE eperson ALTER COLUMN netid TYPE character varying(256); -ALTER TABLE eperson ALTER COLUMN email TYPE character varying(256); -ALTER TABLE eperson ADD COLUMN IF NOT EXISTS welcome_info varchar(30); -ALTER TABLE eperson ADD COLUMN IF NOT EXISTS can_edit_submission_metadata BOOL; - --- LICENSES -CREATE TABLE IF NOT EXISTS license_definition ( - license_id integer NOT NULL, - name varchar(256), - definition varchar(256), - user_registration_id integer, - label_id integer, - created_on timestamp, - confirmation integer DEFAULT 0, - required_info varchar(256) -); - -CREATE TABLE IF NOT EXISTS license_label ( - label_id integer NOT NULL, - label varchar(5), - title varchar(180), - icon bytea, - is_extended boolean DEFAULT false -); - -CREATE TABLE IF NOT EXISTS license_label_extended_mapping ( - mapping_id integer NOT NULL, - license_id integer, - label_id integer -); - -CREATE TABLE IF NOT EXISTS license_resource_mapping ( - mapping_id integer NOT NULL, - bitstream_uuid uuid, - license_id integer -); - -CREATE TABLE IF NOT EXISTS license_resource_user_allowance ( - transaction_id integer NOT NULL, - user_registration_id integer, - mapping_id integer, - created_on timestamp, - token varchar(256) -); - -CREATE TABLE IF NOT EXISTS user_registration ( - user_registration_id integer NOT NULL, - eperson_id UUID, - email character varying(256), - organization character varying(256), - confirmation boolean DEFAULT true -); - -CREATE TABLE IF NOT EXISTS user_metadata ( - user_metadata_id integer NOT NULL, - user_registration_id integer, - metadata_key character varying(64), - metadata_value character varying(256), - transaction_id integer -); - -CREATE TABLE IF NOT EXISTS verification_token ( - verification_token_id integer NOT NULL, - eperson_netid varchar(256), - shib_headers varchar(2048), - token varchar(256), - email varchar(256) -); - --- PREVIEW CONTENT -CREATE TABLE IF NOT EXISTS previewcontent ( - previewcontent_id integer NOT NULL, - bitstream_id uuid NOT NULL, - name varchar(2000), - content varchar(2000), - isDirectory boolean DEFAULT false, - size varchar(256) -); - -CREATE TABLE IF NOT EXISTS preview2preview ( - parent_id integer NOT NULL, - child_id integer NOT NULL, - name varchar(2000) -); - --- SEQUENCES -CREATE SEQUENCE IF NOT EXISTS license_definition_license_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS license_label_label_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS license_label_extended_mapping_mapping_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS license_resource_mapping_mapping_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS license_resource_user_allowance_transaction_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS user_registration_user_registration_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS user_metadata_user_metadata_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS verification_token_verification_token_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -CREATE SEQUENCE IF NOT EXISTS previewcontent_previewcontent_id_seq - START WITH 1 INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1; - -ALTER SEQUENCE license_definition_license_id_seq OWNED BY license_definition.license_id; -ALTER SEQUENCE license_label_label_id_seq OWNED BY license_label.label_id; -ALTER SEQUENCE license_label_extended_mapping_mapping_id_seq OWNED BY license_label_extended_mapping.mapping_id; -ALTER SEQUENCE license_resource_mapping_mapping_id_seq OWNED BY license_resource_mapping.mapping_id; -ALTER SEQUENCE license_resource_user_allowance_transaction_id_seq OWNED BY license_resource_user_allowance.transaction_id; -ALTER SEQUENCE user_metadata_user_metadata_id_seq OWNED BY user_metadata.user_metadata_id; -ALTER SEQUENCE previewcontent_previewcontent_id_seq OWNED BY previewcontent.previewcontent_id; - --- The original left this one commented out; it stays that way. ---ALTER SEQUENCE user_registration_user_registration_id_seq OWNED BY user_registration.eperson_id; - --- COLUMN DEFAULTS -ALTER TABLE ONLY license_definition ALTER COLUMN license_id SET DEFAULT nextval('license_definition_license_id_seq'::regclass); -ALTER TABLE ONLY license_label ALTER COLUMN label_id SET DEFAULT nextval('license_label_label_id_seq'::regclass); -ALTER TABLE ONLY license_label_extended_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_label_extended_mapping_mapping_id_seq'::regclass); -ALTER TABLE ONLY license_resource_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_resource_mapping_mapping_id_seq'::regclass); -ALTER TABLE ONLY license_resource_user_allowance ALTER COLUMN transaction_id SET DEFAULT nextval('license_resource_user_allowance_transaction_id_seq'::regclass); -ALTER TABLE ONLY user_metadata ALTER COLUMN user_metadata_id SET DEFAULT nextval('user_metadata_user_metadata_id_seq'::regclass); -ALTER TABLE ONLY verification_token ALTER COLUMN verification_token_id SET DEFAULT nextval('verification_token_verification_token_id_seq'::regclass); - --- The original left this one commented out; it stays that way. ---ALTER TABLE ONLY user_registration ALTER COLUMN eperson_id SET DEFAULT nextval('user_registration_user_registration_id_seq'::regclass); - --- SEQUENCE BASELINES --- The originals set these to the values carried over from the CLARIN 5 migration. Applying --- them to a populated table would rewind a live sequence, so each one runs only while its --- owning table is still empty. -DO $$ -DECLARE - baseline record; - table_has_rows boolean; -BEGIN - FOR baseline IN - SELECT * FROM (VALUES - ('license_label_extended_mapping_mapping_id_seq', 'license_label_extended_mapping', 991137), - ('license_label_label_id_seq', 'license_label', 19), - ('license_resource_mapping_mapping_id_seq', 'license_resource_mapping', 1382), - ('license_resource_user_allowance_transaction_id_seq', 'license_resource_user_allowance', 241), - ('user_metadata_user_metadata_id_seq', 'user_metadata', 68) - ) AS t(sequence_name, table_name, last_value) - LOOP - CONTINUE WHEN to_regclass(baseline.sequence_name) IS NULL; - CONTINUE WHEN to_regclass(baseline.table_name) IS NULL; - - EXECUTE format('SELECT EXISTS (SELECT 1 FROM %s)', to_regclass(baseline.table_name)) - INTO table_has_rows; - CONTINUE WHEN table_has_rows; - - PERFORM setval(to_regclass(baseline.sequence_name), baseline.last_value, true); - END LOOP; -END $$; - --- CONSTRAINTS -DO $$ -DECLARE - c record; -BEGIN - FOR c IN - SELECT * FROM (VALUES - ('license_definition', 'license_definition_pkey', 'PRIMARY KEY (license_id)'), - ('license_label', 'license_label_pkey', 'PRIMARY KEY (label_id)'), - ('license_label_extended_mapping', 'license_label_extended_mapping_pkey', 'PRIMARY KEY (mapping_id)'), - ('license_resource_mapping', 'license_resource_mapping_pkey', 'PRIMARY KEY (mapping_id)'), - ('license_resource_user_allowance', 'license_resource_user_allowance_pkey', 'PRIMARY KEY (transaction_id)'), - ('user_registration', 'user_registration_pkey', 'PRIMARY KEY (user_registration_id)'), - ('user_metadata', 'user_metadata_pkey', 'PRIMARY KEY (user_metadata_id)'), - ('verification_token', 'verification_token_pkey', 'PRIMARY KEY (verification_token_id)'), - ('previewcontent', 'previewcontent_pkey', 'PRIMARY KEY (previewcontent_id)'), - ('preview2preview', 'preview2preview_pkey', 'PRIMARY KEY (parent_id, child_id)'), - ('license_label_extended_mapping', 'license_definition_license_label_extended_mapping_fk', - 'FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE'), - ('license_label_extended_mapping', 'license_label_license_label_extended_mapping_fk', - 'FOREIGN KEY (label_id) REFERENCES license_label(label_id) ON DELETE CASCADE'), - ('license_resource_mapping', 'license_definition_license_resource_mapping_fk', - 'FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE'), - ('license_resource_mapping', 'bitstream_license_resource_mapping_fk', - 'FOREIGN KEY (bitstream_uuid) REFERENCES bitstream(uuid) ON DELETE CASCADE'), - ('license_resource_user_allowance', 'license_resource_mapping_license_resource_user_allowance_fk', - 'FOREIGN KEY (mapping_id) REFERENCES license_resource_mapping(mapping_id) ON UPDATE CASCADE ON DELETE CASCADE'), - ('license_resource_user_allowance', 'user_registration_license_resource_user_allowance_fk', - 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), - ('license_definition', 'user_registration_license_definition_fk', - 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), - ('user_metadata', 'license_resource_user_allowance_user_metadata_fk', - 'FOREIGN KEY (transaction_id) REFERENCES license_resource_user_allowance(transaction_id) ON UPDATE CASCADE ON DELETE CASCADE'), - ('user_metadata', 'user_registration_user_metadata_fk', - 'FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id)'), - ('previewcontent', 'previewcontent_bitstream_fk', - 'FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid) ON DELETE CASCADE'), - ('preview2preview', 'preview2preview_parent_fk', - 'FOREIGN KEY (parent_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE'), - ('preview2preview', 'preview2preview_child_fk', - 'FOREIGN KEY (child_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE') - ) AS t(table_name, constraint_name, definition) - LOOP - CONTINUE WHEN to_regclass(c.table_name) IS NULL; - CONTINUE WHEN EXISTS ( - SELECT 1 FROM pg_constraint - WHERE conname = c.constraint_name AND conrelid = to_regclass(c.table_name) - ); - - EXECUTE format('ALTER TABLE %s ADD CONSTRAINT %I %s', - to_regclass(c.table_name), c.constraint_name, c.definition); - END LOOP; -END $$; - --- The original left this one commented out; it stays that way. ---ALTER TABLE ONLY license_definition --- ADD CONSTRAINT license_label_license_definition_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id); - -CREATE UNIQUE INDEX IF NOT EXISTS license_definition_license_id_key ON license_definition USING btree (name); - --- OWNERSHIP --- The statements this migration exists for. Unqualified, so they apply to the schema the --- connection actually uses. Skipped when the role is missing, when the object already --- belongs to it, or when the current role may not reassign it -- an install whose objects --- belong to a tenant role keeps them. -DO $$ -DECLARE - target_owner CONSTANT text := 'dspace'; - objects CONSTANT text[] := ARRAY[ - 'license_definition', - 'license_definition_license_id_seq', - 'license_label', - 'license_label_label_id_seq', - 'license_label_extended_mapping', - 'license_label_extended_mapping_mapping_id_seq', - 'license_resource_mapping', - 'license_resource_mapping_mapping_id_seq', - 'license_resource_user_allowance', - 'license_resource_user_allowance_transaction_id_seq', - 'user_registration', - 'user_registration_user_registration_id_seq', - 'user_metadata', - 'user_metadata_user_metadata_id_seq', - 'previewcontent', - 'previewcontent_previewcontent_id_seq', - 'preview2preview' - ]; - object_name text; - object_oid oid; -BEGIN - IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = target_owner) THEN - RAISE NOTICE 'Role % does not exist, leaving object ownership unchanged.', target_owner; - RETURN; - END IF; - - FOREACH object_name IN ARRAY objects LOOP - object_oid := to_regclass(object_name); - CONTINUE WHEN object_oid IS NULL; - CONTINUE WHEN EXISTS ( - SELECT 1 FROM pg_class cls - JOIN pg_roles r ON r.oid = cls.relowner - WHERE cls.oid = object_oid AND r.rolname = target_owner - ); - - BEGIN - EXECUTE format('ALTER TABLE %s OWNER TO %I', object_oid::regclass, target_owner); - EXCEPTION WHEN insufficient_privilege THEN - RAISE NOTICE 'Cannot reassign % to %, leaving its current owner in place: %', - object_oid::regclass, target_owner, SQLERRM; - END; - END LOOP; -END $$; diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Upgrade_to_Lindat_Clarin_schema.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Upgrade_to_Lindat_Clarin_schema.sql new file mode 100644 index 000000000000..319db02003de --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.14__Upgrade_to_Lindat_Clarin_schema.sql @@ -0,0 +1,490 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +-- HANDLE TABLE +ALTER TABLE handle ADD url varchar; +ALTER TABLE handle ADD dead BOOL; +ALTER TABLE handle ADD dead_since TIMESTAMP WITH TIME ZONE; + +-- MetadataField table +-- Because of metashareSchema +ALTER TABLE metadatafieldregistry ALTER COLUMN element TYPE VARCHAR(128); + +-- LICENSES +-- +-- Name: license_definition; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE license_definition ( + license_id integer NOT NULL, + name varchar(256), + definition varchar(256), + user_registration_id integer, + label_id integer, + created_on timestamp, + confirmation integer DEFAULT 0, + required_info varchar(256) +); + +ALTER TABLE license_definition OWNER TO dspace; + +-- +-- Name: license_definition_license_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE license_definition_license_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +ALTER TABLE license_definition_license_id_seq OWNER TO dspace; + +-- +-- Name: license_definition_license_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE license_definition_license_id_seq OWNED BY license_definition.license_id; + +-- +-- Name: license_label; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE license_label ( + label_id integer NOT NULL, + label varchar(5), + title varchar(180), + icon bytea, + is_extended boolean DEFAULT false +); + + +ALTER TABLE license_label OWNER TO dspace; + +-- +-- Name: license_label_extended_mapping; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE license_label_extended_mapping ( + mapping_id integer NOT NULL, + license_id integer, + label_id integer +); + +ALTER TABLE license_label_extended_mapping OWNER TO dspace; + +-- +-- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE license_label_extended_mapping_mapping_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE license_label_extended_mapping_mapping_id_seq OWNER TO dspace; + +-- +-- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE license_label_extended_mapping_mapping_id_seq OWNED BY license_label_extended_mapping.mapping_id; + + +-- +-- Name: license_label_extended_mapping_mapping_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dspace +-- + +SELECT pg_catalog.setval('license_label_extended_mapping_mapping_id_seq', 991137, true); + +-- +-- Name: license_label_label_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE license_label_label_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE license_label_label_id_seq OWNER TO dspace; + +-- +-- Name: license_label_label_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE license_label_label_id_seq OWNED BY license_label.label_id; + + +-- +-- Name: license_label_label_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dspace +-- + +SELECT pg_catalog.setval('license_label_label_id_seq', 19, true); + +-- +-- Name: license_resource_mapping; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE license_resource_mapping ( + mapping_id integer NOT NULL, + bitstream_uuid uuid, + license_id integer +); + + +ALTER TABLE license_resource_mapping OWNER TO dspace; + +-- +-- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE license_resource_mapping_mapping_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE license_resource_mapping_mapping_id_seq OWNER TO dspace; + +-- +-- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE license_resource_mapping_mapping_id_seq OWNED BY license_resource_mapping.mapping_id; + + +-- +-- Name: license_resource_mapping_mapping_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dspace +-- + +SELECT pg_catalog.setval('license_resource_mapping_mapping_id_seq', 1382, true); + + +-- +-- Name: license_resource_user_allowance; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE license_resource_user_allowance ( + transaction_id integer NOT NULL, + user_registration_id integer, + mapping_id integer, + created_on timestamp, + token varchar(256) +); + +ALTER TABLE license_resource_user_allowance OWNER TO dspace; + +-- +-- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE license_resource_user_allowance_transaction_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +ALTER TABLE license_resource_user_allowance_transaction_id_seq OWNER TO dspace; + +-- +-- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE license_resource_user_allowance_transaction_id_seq OWNED BY license_resource_user_allowance.transaction_id; + +-- +-- Name: license_resource_user_allowance_transaction_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dspace +-- + +SELECT pg_catalog.setval('license_resource_user_allowance_transaction_id_seq', 241, true); +-- +-- Name: user_registration; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE user_registration ( + user_registration_id integer NOT NULL, + eperson_id UUID, + email character varying(256), + organization character varying(256), + confirmation boolean DEFAULT true +); + +ALTER TABLE user_registration OWNER TO dspace; + +CREATE SEQUENCE user_registration_user_registration_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +ALTER TABLE user_registration_user_registration_id_seq OWNER TO dspace; + +-- +-- Name: user_registration_user_registration_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +--ALTER SEQUENCE user_registration_user_registration_id_seq OWNED BY user_registration.eperson_id; + +-- +---- Name: user_metadata; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +---- + +CREATE TABLE user_metadata ( + user_metadata_id integer NOT NULL, + user_registration_id integer, + metadata_key character varying(64), + metadata_value character varying(256), + transaction_id integer +); + + +ALTER TABLE user_metadata OWNER TO dspace; + +-- +-- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE user_metadata_user_metadata_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE user_metadata_user_metadata_id_seq OWNER TO dspace; + +-- +-- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE user_metadata_user_metadata_id_seq OWNED BY user_metadata.user_metadata_id; + + +-- +-- Name: user_metadata_user_metadata_id_seq; Type: SEQUENCE SET; Schema: public; Owner: dspace +-- + +SELECT pg_catalog.setval('user_metadata_user_metadata_id_seq', 68, true); + + +-- Name: license_id; Type: DEFAULT; Schema: public; Owner: dspace + + +CREATE TABLE verification_token ( + verification_token_id integer NOT NULL, + eperson_netid varchar(256), + shib_headers varchar(2048), + token varchar(256), + email varchar(256) +); + +CREATE SEQUENCE verification_token_verification_token_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + + +ALTER TABLE ONLY verification_token ALTER COLUMN verification_token_id SET DEFAULT nextval('verification_token_verification_token_id_seq'::regclass); + +ALTER TABLE ONLY license_definition ALTER COLUMN license_id SET DEFAULT nextval('license_definition_license_id_seq'::regclass); + + +-- +-- Name: label_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_label ALTER COLUMN label_id SET DEFAULT nextval('license_label_label_id_seq'::regclass); + + +-- +-- Name: mapping_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_label_extended_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_label_extended_mapping_mapping_id_seq'::regclass); + + +-- +-- Name: mapping_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_resource_mapping ALTER COLUMN mapping_id SET DEFAULT nextval('license_resource_mapping_mapping_id_seq'::regclass); + + +-- +-- Name: transaction_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_resource_user_allowance ALTER COLUMN transaction_id SET DEFAULT nextval('license_resource_user_allowance_transaction_id_seq'::regclass); + +-- +-- Name: user_metadata_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY user_metadata ALTER COLUMN user_metadata_id SET DEFAULT nextval('user_metadata_user_metadata_id_seq'::regclass); + +-- +-- Name: user_registration_id; Type: DEFAULT; Schema: public; Owner: dspace +-- + +--ALTER TABLE ONLY user_registration ALTER COLUMN eperson_id SET DEFAULT nextval('user_registration_user_registration_id_seq'::regclass); + +-- +-- Name: license_definition_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY license_definition + ADD CONSTRAINT license_definition_pkey PRIMARY KEY (license_id); + + +-- +-- Name: license_label_extended_mapping_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY license_label_extended_mapping + ADD CONSTRAINT license_label_extended_mapping_pkey PRIMARY KEY (mapping_id); + + +-- +-- Name: license_label_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY license_label + ADD CONSTRAINT license_label_pkey PRIMARY KEY (label_id); + + +-- +-- Name: license_resource_mapping_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY license_resource_mapping + ADD CONSTRAINT license_resource_mapping_pkey PRIMARY KEY (mapping_id); + + +-- +-- Name: license_resource_user_allowance_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY license_resource_user_allowance + ADD CONSTRAINT license_resource_user_allowance_pkey PRIMARY KEY (transaction_id); + + +CREATE UNIQUE INDEX license_definition_license_id_key ON license_definition USING btree (name); + + +-- +-- Name: license_definition_license_label_extended_mapping_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_label_extended_mapping + ADD CONSTRAINT license_definition_license_label_extended_mapping_fk FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE; + + +-- +-- Name: license_definition_license_resource_mapping_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_resource_mapping + ADD CONSTRAINT license_definition_license_resource_mapping_fk FOREIGN KEY (license_id) REFERENCES license_definition(license_id) ON DELETE CASCADE; + +ALTER TABLE ONLY license_resource_mapping + ADD CONSTRAINT bitstream_license_resource_mapping_fk FOREIGN KEY (bitstream_uuid) REFERENCES bitstream(uuid) ON DELETE CASCADE; + +-- +-- Name: license_label_license_definition_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +--ALTER TABLE ONLY license_definition +-- ADD CONSTRAINT license_label_license_definition_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id); + + +-- +-- Name: license_label_license_label_extended_mapping_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_label_extended_mapping + ADD CONSTRAINT license_label_license_label_extended_mapping_fk FOREIGN KEY (label_id) REFERENCES license_label(label_id) ON DELETE CASCADE; + + +-- +-- Name: license_resource_mapping_license_resource_user_allowance_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_resource_user_allowance + ADD CONSTRAINT license_resource_mapping_license_resource_user_allowance_fk FOREIGN KEY (mapping_id) REFERENCES license_resource_mapping(mapping_id) ON UPDATE CASCADE ON DELETE CASCADE; + +-- +-- Name: user_registration_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY user_registration + ADD CONSTRAINT user_registration_pkey PRIMARY KEY (user_registration_id); + +ALTER TABLE verification_token + ADD CONSTRAINT verification_token_pkey PRIMARY KEY (verification_token_id); + +-- +-- Name: user_registration_license_definition_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_definition + ADD CONSTRAINT user_registration_license_definition_fk FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id); +-- +-- Name: user_registration_license_resource_user_allowance_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY license_resource_user_allowance + ADD CONSTRAINT user_registration_license_resource_user_allowance_fk FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id); + +-- +-- Name: user_metadata_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY user_metadata + ADD CONSTRAINT user_metadata_pkey PRIMARY KEY (user_metadata_id); + +-- +-- Name: license_resource_user_allowance_user_metadata_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY user_metadata + ADD CONSTRAINT license_resource_user_allowance_user_metadata_fk FOREIGN KEY (transaction_id) REFERENCES license_resource_user_allowance(transaction_id) ON UPDATE CASCADE ON DELETE CASCADE; + +-- +-- Name: user_registration_user_metadata_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY user_metadata + ADD CONSTRAINT user_registration_user_metadata_fk FOREIGN KEY (user_registration_id) REFERENCES user_registration(user_registration_id); + +ALTER TABLE eperson + ALTER COLUMN netid TYPE character varying(256); + +ALTER TABLE eperson + ALTER COLUMN email TYPE character varying(256); + +ALTER TABLE metadatafieldregistry + +ALTER COLUMN element TYPE character varying(128); + +ALTER TABLE eperson ADD welcome_info varchar(30); + +ALTER TABLE eperson ADD can_edit_submission_metadata BOOL; diff --git a/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.15__Added_Preview_Tables.sql b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.15__Added_Preview_Tables.sql new file mode 100644 index 000000000000..74b677d73fd5 --- /dev/null +++ b/dspace-api/src/main/resources/org/dspace/storage/rdbms/sqlmigration/postgres/V7.6_2026.09.15__Added_Preview_Tables.sql @@ -0,0 +1,88 @@ +-- +-- The contents of this file are subject to the license and copyright +-- detailed in the LICENSE and NOTICE files at the root of the source +-- tree and available online at +-- +-- http://www.dspace.org/license/ +-- + +-- +-- Name: previewcontent; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE previewcontent ( + previewcontent_id integer NOT NULL, + bitstream_id uuid NOT NULL, + name varchar(2000), + content varchar(2000), + isDirectory boolean DEFAULT false, + size varchar(256) +); + +ALTER TABLE previewcontent OWNER TO dspace; + +-- +-- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE; Schema: public; Owner: dspace +-- + +CREATE SEQUENCE previewcontent_previewcontent_id_seq + START WITH 1 + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +ALTER TABLE previewcontent_previewcontent_id_seq OWNER TO dspace; + +-- +-- Name: previewcontent_previewcontent_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: dspace +-- + +ALTER SEQUENCE previewcontent_previewcontent_id_seq OWNED BY previewcontent.previewcontent_id; + +-- +-- Name: previewcontent_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE ONLY previewcontent + ADD CONSTRAINT previewcontent_pkey PRIMARY KEY (previewcontent_id); + +-- +-- Name: previewcontent_bitstream_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE ONLY previewcontent + ADD CONSTRAINT previewcontent_bitstream_fk FOREIGN KEY (bitstream_id) REFERENCES bitstream(uuid) ON DELETE CASCADE; + +-- +-- Name: preview2preview; Type: TABLE; Schema: public; Owner: dspace; Tablespace: +-- + +CREATE TABLE preview2preview ( + parent_id integer NOT NULL, + child_id integer NOT NULL, + name varchar(2000) +); + +ALTER TABLE preview2preview OWNER TO dspace; + +-- +-- Name: preview2preview_pkey; Type: CONSTRAINT; Schema: public; Owner: dspace; Tablespace: +-- + +ALTER TABLE preview2preview + ADD CONSTRAINT preview2preview_pkey PRIMARY KEY (parent_id, child_id); + +-- +-- Name: preview2preview_parent_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE preview2preview + ADD CONSTRAINT preview2preview_parent_fk FOREIGN KEY (parent_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE; + +-- +-- Name: preview2preview_child_fk; Type: FK CONSTRAINT; Schema: public; Owner: dspace +-- + +ALTER TABLE preview2preview + ADD CONSTRAINT preview2preview_child_fk FOREIGN KEY (child_id) REFERENCES previewcontent(previewcontent_id) ON DELETE CASCADE;