Skip to content

Commit

Permalink
Add tables notes_link and notes_note_link
Browse files Browse the repository at this point in the history
  • Loading branch information
nassibnassar committed Jan 19, 2024
1 parent ac2903a commit 1d329da
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/dbup1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
38 changes: 38 additions & 0 deletions src/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 14 additions & 0 deletions src/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
2 changes: 2 additions & 0 deletions src/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1d329da

Please sign in to comment.