sjacorg / bayanat

Open source data management solution for human rights documentation.
https://bayanat.org/
GNU Affero General Public License v3.0
21 stars 13 forks source link

Updating versions #14

Closed hapee closed 2 years ago

hapee commented 2 years ago

I would like to update from version 7.1 to higher and activate the missing person function. In your documentation your write: This setting needs to be enabled before the creation the database for the Missing Persons fields to be created. flask create-db will not create those fields for existing Actor table. It is possible in theory to backup the database using pg_dump, drop the database and recreate it after enabling this setting, and then import the dump file into the database again. However, we didn't test this

I did test it, it does not work, a lot of errors are in the postgress import and a lot of data is not copied into tables. So I am wondering if you have other recommendations.

sjacgit commented 2 years ago

There are two things you could try, however at your own risk as we haven't verified that they work 100%. First you should upgrade normally to latest version, applying all migration steps as described in the releases.

After that, you can turn on the MISSING_PERSONS settings in .env file and try the following:

pg_dump -a -Fc db > db.sql # backup data only (without schema)
dropdb db 
createdb db
flask create-db # recreate db with missing persons fields, assuming you've activated virtualenv
pg_restore -a --disable-triggers -d db db.sql # restore data only

The --disable-triggers flag with pg_restore will suppress the errors you've been having and import the data while ignore constrains.

The second possible solution you can try if the first one didn't work is to create the db columns manually, again after you upgrade and enable the missing persons extension. You can do that in the psql console of the database:

alter table actor
add column  last_address text,
add column social_networks json,
add column marriage_history character varying,
add column bio_children integer,
add column pregnant_at_disappearance boolean,
add column months_pregnant numeric,
add column missing_relatives boolean,
add column saw_name character varying,
add column saw_address text,
add column saw_email character varying,
add column saw_phone character varying,
add column detained_before character varying,
add column seen_in_detention json,
add column injured json,
add column known_dead json,
add column death_details text,
add column personal_items text,
add column height numeric,
add column weight numeric,
add column physique character varying,
add column hair_loss character varying,
add column hair_type character varying,
add column hair_length character varying,
add column hair_color character varying,
add column facial_hair character varying,
add column posture text,
add column skin_markings json,
add column handedness character varying,
add column glasses boolean,
add column eye_color character varying,
add column dist_char_con character varying,
add column dist_char_acq character varying,
add column physical_habits character varying,
add column other text,
add column phys_name_contact text,
add column injuries text,
add column implants text,
add column malforms text,
add column pain text,
add column other_conditions text,
add column accidents text,
add column pres_drugs text,
add column smoker boolean,
add column dental_record boolean,
add column dentist_info text,
add column teeth_features text,
add column dental_problems text,
add column dental_treatments text,
add column dental_habits text,
add column case_status character varying,
add column reporters json,
add column identified_by character varying,
add column family_notified boolean,
add column hypothesis_based text,
add column hypothesis_status character varying,
add column reburial_location character varying;

Again, we haven't verified either, so please make sure everything is backed-up before you start, and verify the data after any changes.

hapee commented 2 years ago

it looks like the first one did work after all, I will double check and let you know if it really worked.

thanks for your answer, really appreciated.

hapee commented 2 years ago

I copied the documentation and confirm it is working so issue closed and thanks again.