Skip to content

Generate ALTER TABLE SET UNLOGGED/LOGGED when persistence is changed (#9677) - #9768

Closed
pavanmanishd wants to merge 3 commits into
pgadmin-org:masterfrom
pavanmanishd:fix/9677-unlogged-switch
Closed

Generate ALTER TABLE SET UNLOGGED/LOGGED when persistence is changed (#9677)#9768
pavanmanishd wants to merge 3 commits into
pgadmin-org:masterfrom
pavanmanishd:fix/9677-unlogged-switch

Conversation

@pavanmanishd

@pavanmanishd pavanmanishd commented Mar 21, 2026

Copy link
Copy Markdown
Contributor

Closes #9677

Problem

The Unlogged toggle in Table Properties → Advanced has no effect. Toggling it and saving produces no DDL — the relpersistence change was tracked in the form but never written to the update SQL templates.

Fix

Add the missing block to both default/update.sql and 11_plus/update.sql:

{% if data.relpersistence is defined and data.relpersistence != o_data.relpersistence %}
ALTER TABLE IF EXISTS ... SET {% if data.relpersistence %}UNLOGGED{% else %}LOGGED{% endif %};
{% endif %}

The relpersistence field is already fetched by properties.sql (relpersistence = 'u' → true) and tracked in the form; this change wires it through to DDL generation.

Summary by CodeRabbit

  • New Features
    • Table persistence can now be modified to LOGGED or UNLOGGED states when updating table configurations. This functionality is now available across all PostgreSQL versions supported by the application, including PostgreSQL 11 and later versions as well as earlier supported versions, providing users complete flexibility in managing their table durability settings and behaviors.

Add onMouseDown handler to the tab close button that fires layoutDocker.close()
when mouse button 1 (middle click) is pressed. preventDefault() stops the
browser's auto-scroll cursor from appearing.

This matches the standard UX in Chrome, Firefox, and VS Code where middle-click
on a tab closes it.
…istence changes

The Unlogged toggle in Table Properties was read-only — toggling it and
saving did not generate any DDL. Both the default/ and 11_plus/ update.sql
templates were missing the relpersistence alter block.

Add the missing section to both templates:
  ALTER TABLE ... SET UNLOGGED;   (when relpersistence toggled on)
  ALTER TABLE ... SET LOGGED;     (when relpersistence toggled off)

The relpersistence value is already fetched by properties.sql and tracked
in the form; this change wires it through to the DDL generation.
@coderabbitai

coderabbitai Bot commented Mar 21, 2026

Copy link
Copy Markdown

Walkthrough

Added functionality to update table persistence settings (LOGGED/UNLOGGED) in pgAdmin's SQL generation templates for PostgreSQL. Changes include conditional ALTER TABLE statements that execute when table persistence needs modification, with proper Jinja template control flow restructuring in two version-specific template files.

Changes

Cohort / File(s) Summary
Table Persistence Update Templates
web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql, web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql
Added conditional blocks to execute ALTER TABLE ... SET UNLOGGED or SET LOGGED when data.relpersistence differs from o_data.relpersistence. Restructured Jinja template control flow by inserting {% endif %} tags to properly scope the new persistence update conditional block after the existing OIDS update section.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding ALTER TABLE SET UNLOGGED/LOGGED generation when table persistence is modified.
Linked Issues check ✅ Passed The pull request directly addresses issue #9677 by implementing the missing ALTER TABLE SET UNLOGGED/LOGGED DDL generation in both update.sql templates.
Out of Scope Changes check ✅ Passed All changes are scoped to adding persistence toggle support in SQL update templates; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pavanmanishd
pavanmanishd marked this pull request as ready for review March 22, 2026 09:17

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql`:
- Around line 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+.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: adf0b540-773f-4ce0-977d-494c32ad1672

📥 Commits

Reviewing files that changed from the base of the PR and between 2576548 and 5524428.

📒 Files selected for processing (2)
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/11_plus/update.sql
  • web/pgadmin/browser/server_groups/servers/databases/schemas/tables/templates/tables/sql/default/update.sql

@khushboovashi

Copy link
Copy Markdown
Contributor

Hi @pavanmanishd, please address the coderabbitai review comments.

dpage pushed a commit that referenced this pull request Jun 9, 2026
…9768)

Wire the relpersistence change through to the table update SQL across all
version buckets (default, 11_plus, 12_plus, 15_plus) so the Unlogged toggle
emits ALTER TABLE ... SET LOGGED/UNLOGGED on every supported server.

Closes #9677.
@dpage

dpage commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Merged to master as 39684cd (squashed, preserving @pavanmanishd as author).

As part of the merge I completed the fix per @coderabbitai's catch and @khushboovashi's request: the persistence block was missing from the 12_plus and 15_plus update.sql buckets, so as submitted the toggle only worked on PG 11 (EOL). I added the identical block to both, so the fix now covers every supported server (PG 12–18 route to 12_plus/15_plus). Also added a release-notes entry for #9677.

The squash rewrites the SHA so GitHub won't auto-close this — closing manually. Thanks @pavanmanishd!

@dpage dpage closed this Jun 9, 2026
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

@dpage Thanks for the detailed summary and for completing the fix! Great catch on 12_plus and 15_plus — covering the full PG 12–18 range makes the fix actually useful for anyone on a supported server. Congrats to @pavanmanishd on the contribution as well!

(ノ◕ヮ◕)ノ*:・゚✧ 🐇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unlogged switch in Table->Properties->Advanced has no effect

3 participants