Suggestion:
- Reserve index that will be added to name of tables that are going to be exported. Index is assigned to specific tenant which is going to be exorted.
Before creating tables, restrict any write access for tenant that is suppose to migrated with proper RLS policy
- Create table that suppose to be exported
forearch (table : tablesToExport) {
CREATE TABLE export_tab_{index}_{table}
SELECT * FROM {table}
}
-
Export data (in one or multiple files) with pg_dump
-
Create sql script for assertion that checks total amount of records for all tables
IMPORT
- Chec sequnce values in exported database
- Check what is the highest (current value) in sequence
- Alternative, if configuration has information which table and column use specific sequence then based on "export_tab" the value of sequnece that might be required to update can be calculated based on export tables and not current value of sequence which can be higher
- Update sequences in target database
- Import data from files to target database (all constraint for operation has to be turned off) AFTER IMPORT Execute potential script and pass tenant id as argument 8 Delete tables for {index} like export_tab_{index}_{table}