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?
Popular Pragprog topics










Other popular topics










Latest in Pragprog
Latest (all)
Categories:
My Saved Portals
-
None saved yet
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /preact
- /flutter
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /vuejs
- /nim
- /emacs
- /nerves
- /elm