Change or migrate table name in local DB

I have managed to resolve this issue. The problem is that anvil uses some tables that are not visible in the webeditor or when using psql-anvil-app-server to determine if the schema is correct.
During launch the following psql query is performed and compared to the contents of anvil.yaml:

SELECT * FROM app_storage_access JOIN app_storage_tables ON table_id=id

That means that it is also necessary to modify app_storage_access and app_storage_tables. I have managed to perform the migration using the following SQL code:

-- required changes for renaming a the table image_archive to  defect_archive
BEGIN;

-- Update the entry in public.app_storage_access
UPDATE public.app_storage_access
SET python_name = 'defect_archive'
WHERE python_name = 'image_archive';

-- Update the entry in public.app_storage_tables
UPDATE public.app_storage_tables
SET name = 'DefectArchive'
WHERE name = 'ImageArchive';

-- Rename the table
ALTER TABLE app_tables.image_archive
RENAME TO defect_archive;
COMMIT;
1 Like