From 1d329da64f1a3760b8621ecf26606e43d7b67d78 Mon Sep 17 00:00:00 2001 From: Nassib Nassar Date: Thu, 18 Jan 2024 22:54:48 -0500 Subject: [PATCH] Add tables notes_link and notes_note_link --- src/dbup1.cpp | 17 +++++++++++++++++ src/extract.cpp | 38 ++++++++++++++++++++++++++++++++++++++ src/init.cpp | 2 +- src/schema.cpp | 14 ++++++++++++++ src/schema.h | 2 ++ 5 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/dbup1.cpp b/src/dbup1.cpp index 45f6785..013112a 100644 --- a/src/dbup1.cpp +++ b/src/dbup1.cpp @@ -1627,3 +1627,20 @@ void database_upgrade_34(database_upgrade_options* opt) ulog_sql(sql, opt); { etymon::pgconn_result r(opt->conn, sql); } } + +void database_upgrade_35(database_upgrade_options* opt) +{ + dbtype dbt(opt->conn); + + { etymon::pgconn_result r(opt->conn, "BEGIN;"); } + + upgrade_add_new_table_dbsystem("notes_link", opt, dbt, false); + upgrade_add_new_table_dbsystem("notes_note_link", opt, dbt, false); + + string sql = "UPDATE dbsystem.main SET database_version = 34;"; + ulog_sql(sql, opt); + { etymon::pgconn_result r(opt->conn, sql); } + + { etymon::pgconn_result r(opt->conn, "COMMIT;"); } + ulog_commit(opt); +} diff --git a/src/extract.cpp b/src/extract.cpp index 3de8c00..d3b8613 100644 --- a/src/extract.cpp +++ b/src/extract.cpp @@ -545,6 +545,32 @@ void retrieve_direct_notes(const PGresult *res, string* j) " }"; } +void retrieve_direct_notes_link(const PGresult *res, string* j) +{ + string id, object_id, object_type; + pq_get_value_json_string(res, 0, 0, &id); + pq_get_value_json_string(res, 0, 1, &object_id); + pq_get_value_json_string(res, 0, 2, &object_type); + *j = string("") + + " {\n" + + " \"id\": " + id + ",\n" + + " \"objectId\": " + object_id + ",\n" + + " \"objectType\": " + object_type + "\n" + + " }"; +} + +void retrieve_direct_notes_note_link(const PGresult *res, string* j) +{ + string id, link_id; + pq_get_value_json_string(res, 0, 0, &id); + pq_get_value_json_string(res, 0, 2, &link_id); + *j = string("") + + " {\n" + + " \"id\": " + id + ",\n" + + " \"linkId\": " + link_id + "\n" + + " }"; +} + bool try_retrieve_direct(const data_source& source, ldp_log* lg, const table_schema& table, const string& loadDir, extraction_files* ext_files, bool direct_extraction_no_ssl, const char* instance) @@ -567,6 +593,12 @@ bool try_retrieve_direct(const data_source& source, ldp_log* lg, if (table.source_type == data_source_type::notes) { attr = "id,title,content,indexed_content,domain,type_id,pop_up_on_user,pop_up_on_user,created_by,created_date,updated_by,updated_date"; } + if (table.source_type == data_source_type::notes_link) { + attr = "id,object_id,object_type"; + } + if (table.source_type == data_source_type::notes_note_link) { + attr = "note_id AS id,link_id"; + } // Select from table.direct_source_table and write to JSON file. etymon::pgconn_info dbinfo; @@ -621,6 +653,12 @@ bool try_retrieve_direct(const data_source& source, ldp_log* lg, case data_source_type::notes: retrieve_direct_notes(res.result, &j); break; + case data_source_type::notes_link: + retrieve_direct_notes(res.result, &j); + break; + case data_source_type::notes_note_link: + retrieve_direct_notes(res.result, &j); + break; default: throw runtime_error("internal error: unknown value for data_source_type"); } diff --git a/src/init.cpp b/src/init.cpp index b3b7478..5ae1f1b 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -12,7 +12,7 @@ namespace fs = std::filesystem; -static int64_t ldp_latest_database_version = 34; +static int64_t ldp_latest_database_version = 35; database_upgrade_array database_upgrades[] = { nullptr, // Version 0 has no migration. diff --git a/src/schema.cpp b/src/schema.cpp index 9c46270..dbae8ef 100644 --- a/src/schema.cpp +++ b/src/schema.cpp @@ -642,6 +642,20 @@ void ldp_schema::make_default_schema(ldp_schema* schema) table.anonymize = false; table.source_type = data_source_type::rmb; + table.source_type = data_source_type::notes_link; + table.direct_source_table = "mod_notes.link"; + table.name = "notes_link"; + table.source_spec = ""; + schema->tables.push_back(table); + table.source_type = data_source_type::rmb; + + table.source_type = data_source_type::notes_note_link; + table.direct_source_table = "mod_notes.note_link"; + table.name = "notes_note_link"; + table.source_spec = ""; + schema->tables.push_back(table); + table.source_type = data_source_type::rmb; + /////////////////////////////////////////////////////////////////////////// table.module_name = "mod-orders-storage"; diff --git a/src/schema.h b/src/schema.h index ba958e9..843951e 100644 --- a/src/schema.h +++ b/src/schema.h @@ -45,6 +45,8 @@ class column_schema { enum class data_source_type { direct_only, notes, + notes_link, + notes_note_link, rmb, srs_records, srs_marc_records,