PostgreSQL中DELETE的返回值可以修改吗
我试图阻止用户不可撤销地删除 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不确定它的扩展效果如何(取决于您必须管理的空间数量),但我会定期将空间备份到 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!您可以添加一个 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.
我并没有真正遵循您想要实现的目标,但也许您可以将删除语句放在返回 VOID 的函数中,然后调用它。
使用方法:
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.
To use: