
cleaver-party
High Performance PostgreSQL for Rails: AddCheckConstraintTripsCompletedAt p. 75 (paper book P1.0)
Hello @andatki ,
I ran into a problem with the migration suggested p. 75:
class AddCheckConstraintTripsCompletedAt < ActiveRecord::Migration[7.0]
def change
add_check_constraint :trips,
"completed_at > created_at", # Chronologic consistency
name: "trips_completed_after_created"
end
end
I got the following error:
StandardError: An error has occurred, this and all later migrations canceled: (StandardError)
=== Dangerous operation detected #strong_migrations ===
Adding a check constraint key blocks reads and writes while every row is checked.
Instead, add the check constraint without validating existing rows,
then validate them in a separate migration.
class AddCheckConstraintTripsCompletedAt < ActiveRecord::Migration[7.1]
def change
add_check_constraint :trips, “completed_at > created_at”, name: “trips_completed_after_created”, validate: false
end
end
class ValidateAddCheckConstraintTripsCompletedAt < ActiveRecord::Migration[7.1]
def change
validate_check_constraint :trips, name: “trips_completed_after_created”
end
end
Maybe change the migration or add a note about that in the book?
Most Liked

andatki
Thanks for reporting this @cleaver-party. Indeed, I’d probably skip the safe migrations checks from Strong Migrations here, since the process for safely adding a check constraint is important, but beyond the scope of this section. We’ll get a fix in place for the next ebook version and I’ll leave this open until then, and follow up.
Popular Prag Prog topics










Other popular topics










Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /zig
- /scala
- /html
- /debian
- /nixos
- /lisp
- /agda
- /textmate
- /sublime-text
- /react-native
- /kubuntu
- /arch-linux
- /ubuntu
- /revery
- /manjaro
- /django
- /spring
- /diversity
- /nodejs
- /lua
- /julia
- /slackware
- /c
- /neovim