From fe4e2a17cbcb84b7eafd84b2ef3104b849d3fbee Mon Sep 17 00:00:00 2001 From: Gabriel Grubba <70247653+Grubba27@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:43:45 -0300 Subject: [PATCH] FEATURE: Create rake for db migration in plugins (#29163) * FEATURE: Create rake for db migration in plugins before the dev-xp was clunky, we had to create a migration file in core and move it to the plugin. Now we automated this process, we still create the migration file in core but the rake task will move it to the plugin. the usage is: ``` rake plugin:generate_migration[plugin_name,migration_name,migration_args] rake plugin:generate_migration[discourse-automation,add_group_id_to_automation_rule,"group_id:integer"] ``` * DEV: change rake to be a generator for plugin migrations * DEV: trying to add extra class option to migration generator * DEV: revert to have only `plugin_migration_generator` * DEV: remove rake task for plugin migration creation * DEV: remove migration_generator.rb * DEV: remove if because options with `plugin_name` will always be true --- .../rails/plugin_migration_generator.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/generators/rails/plugin_migration_generator.rb diff --git a/lib/generators/rails/plugin_migration_generator.rb b/lib/generators/rails/plugin_migration_generator.rb new file mode 100644 index 00000000000..dd3afe509e5 --- /dev/null +++ b/lib/generators/rails/plugin_migration_generator.rb @@ -0,0 +1,19 @@ +# 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 + "plugins/#{options["plugin_name"]}/db/migrate" + end +end