PostgreSQL中DELETE的返回值可以修改吗

发布于 2024-09-01 12:46:17 字数 478 浏览 11 评论 0原文

我试图阻止用户不可撤销地删除 Confluence wiki 中的空间。我的第一个想法是将 spaces 表重命名为 allspaces,添加一个新列 deleted,并创建一个视图 spaces code> 代替旧表。该视图将仅返回未删除的空格。我创建了三个规则来允许在 spaces 视图上插入、更新和删除。 DELETE 规则仅更改 deleted 字段,从而将其从视图中删除,但所有数据仍保留在数据库中。

现在的问题是 spaces 上的 DELETE 语句从 PostgreSQL 返回 DELETE 0。这会导致 Hibernate 崩溃并引发异常,Confluence 也会崩溃。

无论如何,有没有办法让 PostgreSQL 返回修改的行而不是在 INSTEAD 规则上删除的行。

I am trying to prevent users from being able to irrevocably delete spaces in a Confluence wiki. My first quick thought was to rename the spaces table to allspaces, add a new column deleted, and create a view spaces in place of the old table. The view will only return non-deleted spaces. I have created three rules to allow INSERT, UPDATE, and DELETE on the spaces view. The DELETE rule just changes the deleted field and thus removes it from the view yet all the data stays in the database.

The problem is now DELETE statements on spaces return DELETE 0 from PostgreSQL. This causes Hibernate to flip out and toss an exception and Confluence blows up.

Is there anyway to have PostgreSQL return rows modified instead of rows deleted on an INSTEAD rule.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

南笙 2024-09-08 12:46:17

不确定它的扩展效果如何(取决于您必须管理的空间数量),但我会定期将空间备份到 XML。这可以通过 API 使用 Confluence CLI:

confluence --action exportSpace --space "spaceName" --file "target/output/confluencecli/spaceName.xml"

您可以根据时间轮换这些备份,并仅保留最新的备份当用户删除空间时。

要更进一步,您可以修改实际删除空间的操作 (confluence/spaces/removespace.vm),并插入逻辑以在确认删除之前将空间备份到 XML。这会扩展得更好!

Not sure how well this would scale (depending on the number of spaces you have to manage), but I would periodically backup the space to XML. This can be done easily through the API using Confluence CLI:

confluence --action exportSpace --space "spaceName" --file "target/output/confluencecli/spaceName.xml"

You could rotate these backups based on age and keep only the most recent ones in the event of a space deletion by a user.

To take this a step further, you could modify the action (confluence/spaces/removespace.vm) that actually deletes the space and insert the logic to backup the space to XML before the removal is confirmed. This would scale much nicer!

深陷 2024-09-08 12:46:17

您可以添加一个 ON DELETE 触发器,将已删除的行保存到存档表中。您可以向应用程序添加救援功能以恢复已删除的行。

You could add an ON DELETE trigger which saves the deleted row to an archive table. You can add a rescue feature to your application to recover deleted rows.

一枫情书 2024-09-08 12:46:17

我并没有真正遵循您想要实现的目标,但也许您可以将删除语句放在返回 VOID 的函数中,然后调用它。

CREATE OR REPLACE FUNCTION delete_space(pid integer)
  RETURNS void AS
$BODY$ 
DECLARE aid INTEGER;
BEGIN
    delete from spaces where id=pid;
    return;
END;
$BODY$
  LANGUAGE 'plpgsql';

使用方法:

select * from delete_space(3);  

I'm not really following what you want to achieve, but perhaps you could put the delete statement in a function that returns VOID and then call it it.

CREATE OR REPLACE FUNCTION delete_space(pid integer)
  RETURNS void AS
$BODY$ 
DECLARE aid INTEGER;
BEGIN
    delete from spaces where id=pid;
    return;
END;
$BODY$
  LANGUAGE 'plpgsql';

To use:

select * from delete_space(3);  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文