This page documents how to hash data while its already into postgres.
Enable the package uuid-ossp on postgres to enable random uuid generation. Run the below command on psql prompt
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
Run the below script to create a function for generating a random number within a range
CREATE FUNCTION random_between(low integer, high integer) RETURNS integer STRICT LANGUAGE plpgsql AS $$ BEGIN RETURN floor(random()* (high-low + 1) + low); END; $$; |
Hashing data from couchDB
Use the couch2pg tool to import couchDb data into a postgres as a single table.
Refer to the page Data migration from CouchDb for details on how to import data from couchDB into postgres.
Note: Skip step 7 and 8 on that page since we want to hash the data before migrating to the postgres model.
To hash the data use the below steps in sequential order. You must be having the couchdb
table in the OpenSRP postgres database that will store the hashed data before starting
hashing_data
baseEntityId
to the random uuid that was generated in step 7 above for the dependent documents e.g events, alerts, multimedia etcids_mapping
and person_names
in the public schema of the postgres database being used. Drop the two tables and also the couchDB staging table couchdb
. Use the below commands To hash data that is already on the postgres model modify the script hash_couchdb_doc_id_and_rev.sql to hash the document id and revision of the client tables in both the client
table and client_metadata
table.
Follow steps 5-9 above.