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?