feat(migrate): add AddIndexOnPostsUserId, down and AddSlugToPosts

This commit is contained in:
dualfroz committed 2026-09-06 14:24:37 +02:00
1 parent d9f5a673e3
commit 66ed34b69d
9 files changed
+130

No files matched your search

@@ -0,0 +1,22 @@
class CreateClaims < Prism::Orm::Migration
def up
create_table :claims do |t|
t.integer :post_id
t.integer :user_id
t.datetime :deleted_at
t.timestamps
end
# Belt and braces with Claim's own `validates :user_id, uniqueness:
# { scope: :post_id }`: the model-level check only ever sees rows this
# same process/transaction can already read, whereas this unique index
# is enforced by Store#validate_unique_indexes inside the very same
# transaction the insert itself runs in (see Store#insert), so it
# still catches a duplicate claim even in the hypothetical case of two
# inserts racing without going through Post#with_lock first.
add_index :claims, %i[post_id user_id], unique: true
end
def down
drop_table :claims
end
end