Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
SET {% if data.relhasoids %}WITH{% else %}WITHOUT{% endif %} OIDS;

{% endif %}
{#####################################################}
{## Change table persistence (UNLOGGED / LOGGED) ##}
{#####################################################}
{% if data.relpersistence is defined and data.relpersistence != o_data.relpersistence %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
SET {% if data.relpersistence %}UNLOGGED{% else %}LOGGED{% endif %};

{% endif %}
Comment on lines +54 to 60
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

BASE="web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql"

echo "1) List all table update templates by version:"
fd -t f "update.sql" "$BASE" | sort

echo
echo "2) Check relpersistence block presence in each update template:"
while IFS= read -r f; do
  if rg -n "relpersistence|SET .*UNLOGGED|SET .*LOGGED|Change table persistence" "$f" >/dev/null; then
    echo "HAS    $f"
  else
    echo "MISSING $f"
  fi
done < <(fd -t f "update.sql" "$BASE" | sort)

echo
echo "3) Inspect template-selection logic for server-version routing:"
rg -n -C3 "11_plus|12_plus|15_plus|template_path|update.sql" \
  web/pgadmin/browser/server_groups/servers/databases/schemas/tables

Repository: pgadmin-org/pgadmin4

Length of output: 678


🏁 Script executed:

#!/bin/bash
set -euo pipefail

BASE="web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql"

echo "=== Checking relpersistence block in each update.sql ==="
echo

for version_dir in default 11_plus 12_plus 15_plus; do
    file="$BASE/$version_dir/update.sql"
    echo "--- $version_dir/update.sql ---"
    if [ -f "$file" ]; then
        if rg "relpersistence|UNLOGGED|LOGGED" "$file" >/dev/null 2>&1; then
            echo "✓ Has relpersistence logic"
            rg -n "relpersistence|Change table persistence" "$file" -B2 -A5
        else
            echo "✗ MISSING relpersistence logic"
        fi
    else
        echo "✗ File does not exist"
    fi
    echo
done

echo "=== Checking template routing logic ==="
rg -n "template_path|get_template_path|12_plus|15_plus" \
  web/pgadmin/browser/server_groups/servers/databases/schemas/tables \
  --type py -A3 -B1 | head -100

Repository: pgadmin-org/pgadmin4

Length of output: 12490


🏁 Script executed:

#!/bin/bash
echo "=== 12_plus/update.sql ==="
wc -l web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql
echo
echo "=== First 20 lines of 12_plus/update.sql ==="
head -20 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql

echo
echo "=== 15_plus/update.sql ==="
wc -l web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/15_plus/update.sql
echo
echo "=== First 20 lines of 15_plus/update.sql ==="
head -20 web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/15_plus/update.sql

Repository: pgadmin-org/pgadmin4

Length of output: 2134


🏁 Script executed:

#!/bin/bash
# Check if there's any fallback or warning mechanism
echo "=== Check for any fallback to default template ==="
grep -r "fallback\|default\|relpersistence" \
  web/pgadmin/browser/server_groups/servers/databases/schemas/tables/utils.py \
  web/pgadmin/browser/server_groups/servers/databases/schemas/tables/__init__.py \
  2>/dev/null || echo "No fallback mechanism found"

Repository: pgadmin-org/pgadmin4

Length of output: 3451


Add relpersistence block to 12_plus and 15_plus templates.

The table persistence toggle (UNLOGGED/LOGGED) works for PostgreSQL 11 and earlier, but is missing from the 12_plus and 15_plus update.sql templates. Users on PostgreSQL 12+ cannot modify table persistence through the UI.

Add the following block to both web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/12_plus/update.sql and 15_plus/update.sql:

Diff for both files
{#####################################################}
{## Change table schema ##}
{#####################################################}
{% if data.schema and data.schema != o_data.schema %}
ALTER TABLE IF EXISTS {{conn|qtIdent(o_data.schema, data.name)}}
  SET SCHEMA {{conn|qtIdent(data.schema)}};

{% endif %}
+{#####################################################}
+{## Change table persistence (UNLOGGED / LOGGED) ##}
+{#####################################################}
+{% if data.relpersistence is defined and data.relpersistence != o_data.relpersistence %}
+ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
+    SET {% if data.relpersistence %}UNLOGGED{% else %}LOGGED{% endif %};
+
+{% endif %}
{#####################################################}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql`
around lines 54 - 60, Copy the relpersistence change-block from the 11_plus
update.sql into the 12_plus and 15_plus update.sql templates: add the
conditional that checks if data.relpersistence is defined and differs from
o_data.relpersistence, then run ALTER TABLE IF EXISTS
{{conn|qtIdent(data.schema, data.name)}} SET {% if data.relpersistence
%}UNLOGGED{% else %}LOGGED{% endif %}; ensuring the same Jinja condition and
qtIdent usage are used so table persistence can be toggled for PostgreSQL 12+
and 15+.

{#####################################################}
{## Change tablespace ##}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
SET {% if data.relhasoids %}WITH{% else %}WITHOUT{% endif %} OIDS;

{% endif %}
{#####################################################}
{## Change table persistence (UNLOGGED / LOGGED) ##}
{#####################################################}
{% if data.relpersistence is defined and data.relpersistence != o_data.relpersistence %}
ALTER TABLE IF EXISTS {{conn|qtIdent(data.schema, data.name)}}
SET {% if data.relpersistence %}UNLOGGED{% else %}LOGGED{% endif %};

{% endif %}
{#####################################################}
{## Change tablespace ##}
Expand Down