fix: use current_database() in TimescaleDB migration

Previous version used hardcoded 'towerops_dev' which doesn't exist in production.
Now uses current_database() to get the actual database name at runtime.

This fixes the crash: ERROR 3D000 (invalid_catalog_name) database "towerops_dev" does not exist
This commit is contained in:
Graham McIntire 2026-03-05 07:53:50 -06:00
parent be1add2e1a
commit 212f9089e0
No known key found for this signature in database

View file

@ -5,16 +5,23 @@ defmodule Towerops.Repo.Migrations.IncreaseTimescaledbDecompressionLimit do
# Increase TimescaleDB tuple decompression limit to unlimited (0)
# This is needed for large interface sync operations during device discovery
# that can touch 100k+ compressed tuples in a single transaction
execute "ALTER DATABASE #{db_name()} SET timescaledb.max_tuples_decompressed_per_dml_transaction = 0"
#
# Use current_database() to get the actual database name at runtime
execute """
DO $$
BEGIN
EXECUTE 'ALTER DATABASE ' || current_database() || ' SET timescaledb.max_tuples_decompressed_per_dml_transaction = 0';
END $$;
"""
end
def down do
# Restore default limit of 100,000
execute "ALTER DATABASE #{db_name()} SET timescaledb.max_tuples_decompressed_per_dml_transaction = 100000"
end
defp db_name do
config = Application.get_env(:towerops, Towerops.Repo)
config[:database] || "towerops_dev"
execute """
DO $$
BEGIN
EXECUTE 'ALTER DATABASE ' || current_database() || ' SET timescaledb.max_tuples_decompressed_per_dml_transaction = 100000';
END $$;
"""
end
end