Recreate ETL schema for an implementation

Clearing ETL schema and rows corresponding to it in the database. The next run of the ETL process will recreate the schema and database.

Ensure that the ETL process is not running

This you can do by disabling the cron job by commenting the job using the# and saving. Also, check that the ETL job is not running already by checking the java process.

sudo su openchs
# disable by commenting
crontab -e

For standalone organizations

select delete_etl_metadata_for_schema('$impl_schema', '$impl_db_user');
set role $impl_schema;  
drop schema $impl_schema cascade;

delete from entity_sync_status where db_user = '$impl_db_user';

delete from index_metadata where table_metadata_id 
    in (select id from table_metadata where schema_name = '$impl_schema');

delete from column_metadata where table_id 
    in (select id from table_metadata where schema_name = '$impl_schema');

delete from table_metadata  
        where schema_name = '$impl_schema';

For organization groups

select delete_etl_metadata_for_org('$impl_schema', '$impl_db_user');
set role openchs;  
drop schema $impl_schema cascade;

delete from entity_sync_status where schema_name = '$impl_schema';

delete from index_metadata where table_metadata_id 
    in (select id from table_metadata where schema_name = '$impl_schema');

delete from column_metadata where table_id 
    in (select id from table_metadata where schema_name = '$impl_schema');

delete from table_metadata where schema_name = '$impl_schema';

Run ETL process for an organization/group or for all the organization/groups.

sudo su openchs;
cd /opt/avni-etl/

### Check for one schema (organisation or organisation group)
./start.sh $schema_name

### Check for all organisations
./start.sh

Enable the cron

Uncomment the commented cron job.