数据库mysql编辑,批准数据库编辑-mysql

本文介绍了一种通过影子表实现数据库变更审批的方法。当用户提交更改请求时,这些请求会被记录到影子表中,待管理员审批后再更新到实际数据库。此方案允许管理员审查并批准更改,确保数据的一致性和准确性。

I currently have a database which many users can access and make changes to. The is also a log database that stores all changes to tables within the database using triggers.

I would like to add the ability to approve edits before they are changed in the database.

What would be the best way to go about this?

解决方案

We have something similar on one of our sites, we've added a bunch of tables:

users sites ... etc

Then we have a bunch of shadow tables:

users-shadow sites-shadow ... etc

The shadow tables have identical structures to the real tables except for an added line for the user who made the change. So first we use this query when a change is submitted by a user who needs to have his/her database actions approved:

REPLACE INTO users-shadow (user_mod,id,username,password,salt...) VALUES (16,50,'bob','stuff','salt'...);

Obviously, make sure this isn't open to injection, use prepared statements etc.

When approved, a row in the shadow table is simply removed from the shadow table, the user_mod value dropped and changes (non-null values) inserted into the real table (or updated if an id is specified, using REPLACE syntax). We do this logic in perl so sadly don't have any SQL on hand for it.

Remember that SQL REPLACE does a DELETE and an INSERT rather than an UPDATE. You will need to amend any triggers to allow for this behaviour.

Note: The reason we didn't use an 'approve' flag was that we needed the ability to amend existing records, of course we couldn't have multiple records with the same primary key.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值