Skip to content

Commit

Permalink
cmr-9193: add option to not use metadata column in aurora postgres db
Browse files Browse the repository at this point in the history
  • Loading branch information
zimzoom committed Aug 24, 2023
1 parent e13f4b2 commit 4ea548d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion aurora-postgres-lib/src/cmr/aurora/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
"Postgres database master password"
{:default "admin"})

(defconfig aurora-toggle
(defconfig aurora-toggle ;; prototype only
"Three-way toggle for Aurora functionality. 'aurora-off' uses only Oracle, 'aurora-on' uses both Oracle and Aurora, and 'aurora-only' uses only Aurora"
{:default "aurora-off"})

(defconfig aurora-metadata? ;; prototype only
"Whether or not to populate the metadata column in the Aurora database."
{:default false :type Boolean})
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
"id INTEGER,
concept_id VARCHAR(255) NOT NULL,
native_id VARCHAR(1030) NOT NULL,
metadata BYTEA NOT NULL,
metadata BYTEA,
format VARCHAR(255) NOT NULL,
revision_id INTEGER DEFAULT 1 NOT NULL,
revision_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
Expand Down
11 changes: 8 additions & 3 deletions metadata-db-app/src/cmr/metadata_db/data/oracle/concepts.clj
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,20 @@
(string/join "," cols)
seq-name
(string/join "," (repeat (count values) "?")))
;; replace instances of 'false' with 0 and 'true' with 1 for Postgres 'deleted' column
pg-values (map #(if (boolean? %) (if % 1 0) %) values)
;; if set to not use metadata column in Aurora database, then remove it and replace with nil
pg-values (if (aurora-config/aurora-metadata?)
values
(map #(if (or (string? %) (number? %) (boolean? %) (nil? %)) % nil) values))
;; postgres does not convert boolean to integer automatically on insert like oracle does.
;; 'irl' we will make this a boolean column bc postgres supports that data type.
pg-values (map #(if (boolean? %) (if % 1 0) %) pg-values)
pg-stmt (format (str "INSERT INTO %s (id, %s, transaction_id) VALUES "
"(NEXTVAL('%s'),%s,NEXTVAL('GLOBAL_TRANSACTION_ID_SEQ'))")
table
(string/join "," cols)
seq-name
(string/join "," (repeat (count pg-values) "?")))]
(trace "Executing" stmt "with values" (pr-str pg-values))
(trace "Executing" pg-stmt "with values" (pr-str pg-values))
(when (not= "dynamo-only" (dynamo-config/dynamo-toggle))
(info "ORT Runtime of Oracle save-concept: " (first (util/time-execution
(j/db-do-prepared db stmt values)))) " ms.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
concept_id VARCHAR(255) NOT NULL,
native_id VARCHAR(250) NOT NULL,
parent_collection_id VARCHAR(255) NOT NULL,
metadata BYTEA NOT NULL,
metadata BYTEA,
format VARCHAR(255) NOT NULL,
revision_id INTEGER DEFAULT 1 NOT NULL,
revision_date TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL,
Expand Down

0 comments on commit 4ea548d

Please sign in to comment.