Uploaded image for project: 'mod-source-record-manager'
  1. mod-source-record-manager
  2. MODSOURMAN-583

Schema name can't replace in snippet (schema.json)

    XMLWordPrintable

Details

    • eHoldings Sprint 125
    • 1
    • Spitfire
    • R3 2021 Bug Fix

    Description

      Migrating mod-source-record-manager fails with this error

      { "message": "type \"rule_type\" already exists", "severity": "ERROR", "code": "42710", "where": "SQL statement \"create type rule_type AS ENUM ('MARC_BIB', 'MARC_HOLDING')\"
      PL/pgSQL function inline_code_block line 1 at SQL statement", "file": "typecmds.c", "line": "1191", "routine": "DefineEnum" }" 

      while executing this snippet:

      https://github.com/folio-org/mod-source-record-manager/blob/v3.2.0/mod-source-record-manager-server/src/main/resources/templates/db_scripts/schema.json#L167-170

      {
        "run": "after",
        "snippet": "DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE t.typname = 'rule_type' AND n.nspname = '${myuniversity}_${mymodule}') THEN create type rule_type AS ENUM ('MARC_BIB', 'MARC_HOLDING'); END IF; END $$; ALTER TABLE mapping_rules ADD COLUMN IF NOT EXISTS record_type rule_type NOT NULL DEFAULT 'MARC_BIB';",
        "fromModuleVersion": "mod-source-record-manager-3.2.0"
      }

      A snippet in schema.json must be a single line. This is the snipped reformatted for readability to help with debugging this issue:

      DO $$
      BEGIN
        IF NOT EXISTS (SELECT 1 FROM pg_type t
                       JOIN pg_enum e ON t.oid = e.enumtypid
                       JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace
                       WHERE t.typname = 'rule_type' AND n.nspname = '${myuniversity}_${mymodule}')
        THEN create type rule_type AS ENUM ('MARC_BIB', 'MARC_HOLDING');
        END IF;
      END $$;
      ALTER TABLE mapping_rules
        ADD COLUMN IF NOT EXISTS record_type rule_type NOT NULL DEFAULT 'MARC_BIB';

      The log shows that the placeholderĀ ${myuniversity}_${mymodule} is NOT replaced by the actual values:

      trying to execute: {}           DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE t.typname = 'rule_type' AND n.nspname = '${myuniversity}_${mymodule}') THEN create type rule_type AS ENUM ('MARC_BIB', 'MARC_HOLDING'); END IF; END $$; ALTER TABLE mapping_rules ADD COLUMN IF NOT EXISTS record_type rule_type NOT NULL DEFAULT 'MARC_BIB';" 

      TestRail: Results

        Attachments

          Issue Links

            Activity

              People

                Oleksandr Dekin Oleksandr Dekin
                Oleksii Petrenko Oleksii Petrenko
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved:

                  TestRail: Runs

                    TestRail: Cases