Skip to content

Instantly share code, notes, and snippets.

@Grubba27
Created October 17, 2024 21:07
Show Gist options
  • Save Grubba27/1f764790df4ed7a039c47061890ab063 to your computer and use it in GitHub Desktop.
Save Grubba27/1f764790df4ed7a039c47061890ab063 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "rails/generators/active_record/migration/migration_generator"
class Rails::MigrationGenerator < ActiveRecord::Generators::MigrationGenerator
class_option :plugin_name,
type: :string,
banner: "plugin_name",
desc: "The plugin name to generate the migration into."
source_root "#{Gem.loaded_specs["activerecord"].full_gem_path}/lib/rails/generators/active_record/migration/templates"
private
def db_migrate_path
if options["plugin_name"]
"plugins/#{options["plugin_name"]}/db/migrate"
else
"db/migrate"
end
end
end
# frozen_string_literal: true
require "rails/generators/active_record/migration/migration_generator"
class Rails::PluginMigrationGenerator < ActiveRecord::Generators::MigrationGenerator
class_option :plugin_name,
type: :string,
banner: "plugin_name",
desc: "The plugin name to generate the migration into.",
required: true
source_root "#{Gem.loaded_specs["activerecord"].full_gem_path}/lib/rails/generators/active_record/migration/templates"
private
def db_migrate_path
if options["plugin_name"]
"plugins/#{options["plugin_name"]}/db/migrate"
else
"db/migrate"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment