Sha256: 2a03a13b71dddceac7f4af084c52b854ea4d4e2de9c9284aafe47da26f95a6ea

Contents?: true

Size: 1.59 KB

Versions: 6

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

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

module PaperTrailAssociationTracking
  # Installs PaperTrail in a rails app.
  class AddForeignTypeToVersionAssociationsGenerator < ::Rails::Generators::Base
    include ::Rails::Generators::Migration

    # Class names of MySQL adapters.
    # - `MysqlAdapter` - Used by gems: `mysql`, `activerecord-jdbcmysql-adapter`.
    # - `Mysql2Adapter` - Used by `mysql2` gem.
    MYSQL_ADAPTERS = [
      "ActiveRecord::ConnectionAdapters::MysqlAdapter",
      "ActiveRecord::ConnectionAdapters::Mysql2Adapter"
    ].freeze

    source_root File.expand_path("../templates", __FILE__)

    desc "Generates (but does not run) a migration to add a the foreign_type column to the version_associations table after upgrading from v1.0 or earlier."

    def create_migrations
      add_paper_trail_migration("add_foreign_type_to_version_associations")
    end

    def self.next_migration_number(dirname)
      ::ActiveRecord::Generators::Base.next_migration_number(dirname)
    end

    protected

    def add_paper_trail_migration(template)
      migration_dir = File.expand_path("db/migrate")
      if self.class.migration_exists?(migration_dir, template)
        ::Kernel.warn "Migration already exists: #{template}"
      else
        migration_template(
          "#{template}.rb.erb",
          "db/migrate/#{template}.rb",
          migration_version: migration_version
        )
      end
    end

    private

    def migration_version
      "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
trusty-cms-7.0.9.1 vendor/bundle/ruby/3.3.0/gems/paper_trail-association_tracking-2.2.1/lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
paper_trail-association_tracking-2.2.1 lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
paper_trail-association_tracking-2.2.0 lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
paper_trail-association_tracking-2.1.3 lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
paper_trail-association_tracking-2.1.1 lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb
paper_trail-association_tracking-2.1.0 lib/generators/paper_trail_association_tracking/add_foreign_type_to_version_associations_generator.rb