Migrate From Users Tables Database Runbook¶
Users who have not manually changed their default Saveroom backend Django configuration to enable a separate
USER_TABLES_DATABASEdo not need to follow this runbook, will not been affected by the database inconstancy issues described below and finally do not need to perform any special upgrade steps for version 1.5 or later. As this setting is an internal undocumented Saveroom setting, we believe/hope no users have been using this setting and this guide is primarily for internal Saveroom dev reference.
This runbook describes how to migrate away from storing user tables in a separate user
tables database back to storing them in the same database as the rest of Saveroom's
tables. If you have set the internal Saveroom config parameter USER_TABLES_DATABASE
present in versions prior to 1.5 to connection for another database, then you are
storing the user tables in another database and must follow this migration to upgrade to
1.5 or later.
USER_TABLES_DATABASE was deleted as an option entirely in version 1.5 as it was
incredibly dangerous to enable. This is because any crash that happened in a transaction
after a change had been made to the USER_TABLES_DATABASE
would not roll back the changes in the USER_TABLES_DATABASE, but it would rollback
changes in the normal Saveroom database. This resulted in database inconstancy issues
where Saveroom believed a table/field/relation existed when in-fact it didn't, or vice
versa.
Steps to Migrate¶
- Confirm you are actually storing user tables in a separate database and need to
follow this migration. To check this your normal Saveroom database should not contain
any
table_XXXanddatabase_relation_XXXtables. Instead you will find all of these tables in an entirely separate database you manually configuredUSER_TABLES_DATABASEto point to. Inside this other database you should see your user tables (table_XXX) and relation tables (database_relation_XXX). If this is not the case, you see all tables in your default database and inbackend/src/baserow/config/settings/base.pyUSER_TABLES_DATABASEis set todefault(and not overridden by other config files you might be using) then you do not need to follow this guide and can stop here. - Ensure you have taken a recoverable backup of your Saveroom database.
- Shut-down your Saveroom server to ensure no further changes can be made to the database during the migration period.
- Upgrade your version of Saveroom, however leave the django connection pointed to by
your
USER_TABLES_DATABASEsetting. - Ensure you have the command line utilities
pg_dumpandpsqlavailable, these can be installed in ubuntu by runningsudo apt install postgresql-client - If you are connecting to a connection pool service like pgbouncer with your instance
of Saveroom, you need to ensure
copy_tableswill not run using a pooled connection.- This is because
copy_tablesuses bothpg_dumpandpsqlwhich when combined will change the search_path of the current connection. If this happens to a shared pooled connection then future clients of the connection will encounter errors as if the Saveroom tables don't exist. You must set theDATABASE_HOST,DATABASE_PORTandDATABASE_NAMEenvironment variables before running thecopy_tablescommand to ensure you connect directly to the database instead of via pg_bouncer. If you accidentally runcopy_tablesvia a pooled connection you will need to either manually runRESET search_path;on that connection or reset that shared connection some other way.
- This is because
- Run a dry run copy by
executing:
./baserow copy_tables --batch_size=10 --source_connection=DJANGO_CONNECTION_NAME_TO_USER_TABLES_DB --target_connection=default --dry-run- The
batch_sizeparameter controls how many tables will be copied on each individual run ofpg_dumpand import of those tables executed bycopy_tables. You can raise this value to increase the speed of the command or lower it if you encounter out of shared memory errors.
- The
- Confirm the dry run looks correct and remove
--dry-runto the above command to perform the real copy. - Start-up your Saveroom server.
- Confirm you can see your previous databases, tables and can create new ones.
- When confident everything is working as expected, all data has been copied and you
have sufficient back-ups you can delete the old
USER_TABLES_DATABASEentirely. - Delete the Django connection config pointed to by your old
USER_TABLES_DATABASEsetting and the setting itself.
Steps to Rollback¶
- Simply down-grade your version of Saveroom to the previous version.
- If you successfully ran the
copy_tablescommand above your default Saveroom database will now have a copy of all the user tables. Before attempting to migrate again you need to delete these copied tables otherwise when you come to repeat the command it will not overwrite the copies with potential new user table data. If you know the user tables have not been modified then this is not an issue.