上下文:我正在尝试拆分一个帖子。为此,我认为我需要:
- 在主题中创建一个新帖子。
- 编辑两个帖子的内容,按我想要的方式。
- 将我创建的帖子的所有者更改为与原始帖子匹配。
- 更改我创建的帖子的时间戳,使其与原始帖子匹配(也许增加几秒钟)。
- 运行
posts:reorder_posts[topic_id]将我的回复移到主题中的正确位置。
我尝试的第一件事是调用 posts:reorder_post,“只是看看”,但它失败了:
root@discourse1-app:/var/www/discourse# rake “posts:reorder_posts[879]”
rake aborted!
PG::UniqueViolation: ERROR: duplicate key value violates unique constraint “post_timings_unique”
DETAIL: Key (topic_id, post_number, user_id)=(879, 93, 1) already exists.
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:110:in `exec'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/rack-mini-profiler-3.0.0/lib/patches/db/pg.rb:110:in `async_exec'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:209:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `block in run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `block in with_lock'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:34:in `with_lock'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/active_record_postgres/connection.rb:38:in `run'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/mini_sql-1.4.0/lib/mini_sql/postgres/connection.rb:181:in `exec'
/var/www/discourse/lib/tasks/posts.rake:383:in `block (3 levels) in <main>'
/var/www/discourse/lib/tasks/posts.rake:366:in `each'
/var/www/discourse/lib/tasks/posts.rake:366:in `block (2 levels) in <main>'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activesupport-7.0.4.1/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/connection_adapters/abstract/database_statements.rb:316:in `transaction'
/var/www/discourse/vendor/bundle/ruby/3.1.0/gems/activerecord-7.0.4.1/lib/active_record/transactions.rb:209:in `transaction'
/var/www/discourse/lib/tasks/posts.rake:329:in `block in <main>'
/usr/local/bin/bundle:25:in `load'
/usr/local/bin/bundle:25:in `<main>'
Tasks: TOP => posts:reorder_posts
(See full trace by running task with --trace)
有趣的是,我在主题中没有看到任何编号为 93 的帖子。我看到 92 和 94。用户 1 是我,但帖子 92 和 94 不是我的。
我之前拆分过主题,所以也许 93 移动到了另一个主题,我不知道。