douchuanchai2793 2015-07-16 18:59
浏览 73
已采纳

事务中数据库查询的时间戳

I'm using DB::transaction and SoftDeletes.

For those unfamiliar with Laravel the SoftDelete functionality of Laravel abstracts away the setting / querying of rows in the database. When a record is deleted the field deleted_at is given a timestamp otherwise this field is null. This field is then used on querying to only get non deleted rows.

Currently I have a script that runs every day that deletes all the soft deleted entries that are older than 7 days.

enter image description here This is where my question/problem is. What if my DB::transaction spanned for let's say 10 seconds and add the end writes to Table A and Table B so that the entries in both tables have a different timestamp.

I can picture a scenario where when the cleanup script executes it could delete HALF of the entry records.

My question then is

  1. would a DB::transaction give the same timestamp to all the records?
  2. if not how can I remedy this problem?
  • 写回答

1条回答 默认 最新

  • dts777777 2015-07-16 19:26
    关注

    The only way I can seeing it working, as it seems mission critical that your data isn't messed up with a partial restore as you say, is to include a transaction number in your affected tables.

    The cleanup routine would need to be tweaked. A transaction cannot be soft deleted and subsequently wiped unless all the timestamps in the transaction exceed 7 days.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效