Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ config.solid_errors.destroy_after = 30.days
config.solid_errors.destroy_after = 6.months
```

#### Checking the schema after an upgrade

When a release changes the schema, [UPGRADE.md](UPGRADE.md) describes the migration. To have your test suite fail until you've applied it, assert that the errors database has everything the installed version uses:

```ruby
# test/solid_errors_test.rb
require "test_helper"

class SolidErrorsTest < ActiveSupport::TestCase
test "the errors database is up to date" do
assert SolidErrors.migrated?
end
end
```

### Examples

There are only two screens in the dashboard.
Expand Down
11 changes: 11 additions & 0 deletions lib/solid_errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def password
@password ||= ENV["SOLIDERRORS_PASSWORD"] || @@password
end

# Whether the errors database has every table and column this version reads and writes.
# Assert it in your test suite to catch a schema change you haven't applied yet.
def migrated?
{
SolidErrors::Error => %w[exception_class message severity source resolved_at fingerprint created_at updated_at],
SolidErrors::Occurrence => %w[error_id backtrace context created_at updated_at]
}.all? do |model, columns|
model.table_exists? && (columns - model.column_names).empty?
end
end

def send_emails?
send_emails && email_to.present? && !ActiveSupport::IsolatedExecutionState[:solid_errors_without_emails]
end
Expand Down
26 changes: 26 additions & 0 deletions test/solid_errors/migrated_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "test_helper"

class SolidErrors::MigratedTest < ActiveSupport::TestCase
teardown do
SolidErrors::Error.reset_column_information
SolidErrors::Occurrence.reset_column_information
end

test "migrated when the errors database has the current schema" do
assert SolidErrors.migrated?
end

test "not migrated when a column this version uses is missing" do
ActiveRecord::Base.connection.remove_column :solid_errors, :fingerprint
SolidErrors::Error.reset_column_information

assert_not SolidErrors.migrated?
end

test "not migrated when a table is missing" do
ActiveRecord::Base.connection.drop_table :solid_errors_occurrences
SolidErrors::Occurrence.reset_column_information

assert_not SolidErrors.migrated?
end
end
Loading