Fixes #17
There was no validation in place to prevent events from having an ends_at datetime before starts_at, which is invalid data. Event starts at 9am, ends at 8am the same day??? This new validation prevents that.
And now that we have that validation we can fix our existing data.
The difference between end and start for the effected events are all over the place. They range from 30 minutes to 22 hours. We're going to:
- get a backup of the DB right before we deploy
- deploy which will fix all bad events to 2h events (ends_at 2 hours after starts_at)
- run some code on the backup to generate a list of changed events
- email the orgs with links to all the events so they can do a manual audit if that's important to them.
Code to run on backup before deploying
- get db backup
- restore db backup locally
Organization.find_each do |org|
puts "## #{org.name}"
puts
org.events.where("ends_at < starts_at").find_each do |event|
shift = event.shift_event.shift
zone = org.time_zone
puts "* [#{event.title}](https://rootable.org/shift_event_occurrences/#{shift.id}-#{event.starts_at.in_time_zone(zone).to_i})"
end
puts
end
Fixes #17
There was no validation in place to prevent events from having an `ends_at` datetime _before_ `starts_at`, which is invalid data. Event starts at 9am, ends at 8am the same day??? This new validation prevents that.
And now that we have that validation we can fix our existing data.
The difference between end and start for the effected events are all over the place. They range from 30 minutes to 22 hours. We're going to:
* get a backup of the DB right before we deploy
* deploy which will fix all bad events to 2h events (ends_at 2 hours after starts_at)
* run some code on the backup to generate a list of changed events
* email the orgs with links to all the events so they can do a manual audit if that's important to them.
<details>
<summary>Code to run on backup before deploying</summary>
* get db backup
* restore db backup locally
```ruby
Organization.find_each do |org|
puts "## #{org.name}"
puts
org.events.where("ends_at < starts_at").find_each do |event|
shift = event.shift_event.shift
zone = org.time_zone
puts "* [#{event.title}](https://rootable.org/shift_event_occurrences/#{shift.id}-#{event.starts_at.in_time_zone(zone).to_i})"
end
puts
end
```
</details>