Skip to content

Commit

Permalink
Merge pull request #60 from fractaledmind/simplify-installer
Browse files Browse the repository at this point in the history
Slim down installer and have it use a final schema instead of migrations
  • Loading branch information
fractaledmind committed Sep 9, 2024
2 parents 01a1965 + 20309d1 commit a9baae7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/generators/solid_errors/install/USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Example:
bin/rails generate solid_errors:install

This will perform the following:
Installs solid_errors migrations
Adds solid_errors db schema
21 changes: 2 additions & 19 deletions lib/generators/solid_errors/install/install_generator.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
# frozen_string_literal: true

require "rails/generators"
require "rails/generators/active_record"

module SolidErrors
#
# Rails generator used for setting up SolidErrors in a Rails application.
# Run it with +bin/rails g solid_errors:install+ in your console.
#
class InstallGenerator < Rails::Generators::Base
include ActiveRecord::Generators::Migration

source_root File.expand_path("templates", __dir__)

class_option :database, type: :string, aliases: %i[--db], desc: "The database for your migration. By default, the current environment's primary database is used."
class_option :skip_migrations, type: :boolean, default: nil, desc: "Skip migrations"

# Generates monolithic migration file that contains all database changes.
def create_migration_file
return if options[:skip_migrations]

migration_template "create_solid_errors_tables.rb.erb", File.join(db_migrate_path, "create_solid_errors_tables.rb")
end

private

def migration_version
"[#{ActiveRecord::VERSION::STRING.to_f}]"
def add_solid_errors_db_schema
template "db/errors_schema.rb"
end
end
end

This file was deleted.

27 changes: 27 additions & 0 deletions lib/generators/solid_errors/install/templates/errors_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

ActiveRecord::Schema[7.1].define(version: 1) do
create_table "solid_errors", force: :cascade do |t|
t.text "exception_class", null: false
t.text "message", null: false
t.text "severity", null: false
t.text "source"
t.datetime "resolved_at"
t.string "fingerprint", limit: 64, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["fingerprint"], name: "index_solid_errors_on_fingerprint", unique: true
t.index ["resolved_at"], name: "index_solid_errors_on_resolved_at"
end

create_table "solid_errors_occurrences", force: :cascade do |t|
t.integer "error_id", null: false
t.text "backtrace"
t.json "context"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["error_id"], name: "index_solid_errors_occurrences_on_error_id"
end

add_foreign_key "solid_errors_occurrences", "solid_errors", column: "error_id"
end

0 comments on commit a9baae7

Please sign in to comment.