Tracker #19454

Mark plugin migrations to be able to run them separately for each plugin.

Added by Shimon Shtein 8 months ago. Updated 7 months ago.

Status:Assigned% Done:

0%

Priority:Normal
Assigned To:Shimon Shtein
Category:Plugins-Engines
Target version:Team Ivan Iteration 15
Difficulty: Bugzilla link:
Found in release:
Story points-
Velocity based estimate-

Description

Rails migrations have a nice feature called "scope" (as described here: http://edgeguides.rubyonrails.org/engines.html#engine-setup).
This feature enables running only migrations that belong to a certain scope.
I propose using this feature in our plugins to mark plugin's migrations, so we will be able to migrate up or down only those migrations. Effectively it will enable us to uninstall every table that belonged to a plugin.

In order to use scopes, migrations should be named accordingly: [timestamp]_[migration_name].[scope].rb (the change is adding the ".scope" to filename).

Once all the migrations are named that way, we can migrate them up or down using:

# set up a plugin:
rake db:migrate SCOPE=my_plugin

# remove the plugin from DB:
rake db:migrate SCOPE=my_plugin VERSION=0

Related issues

Related to Foreman - Feature #3588: Uninstall plugins - from GUI or command line New 11/06/2013
Duplicated by Foreman - Feature #16595: Add scoping to plugin migrations. Duplicate 09/18/2016
Blocked by Foreman - Feature #19589: Add an option to create plugin migrations with properly m... Closed 05/18/2017

History

#1 Updated by Shimon Shtein 8 months ago

  • Related to Feature #3588: Uninstall plugins - from GUI or command line added

#2 Updated by Dominic Cleal 8 months ago

Isn't this the same as #16595?

In both cases, I think this needs filing against the plugin(s) you intend to change, not Foreman, unless there's a code change not mentioned that's required in Foreman.

#3 Updated by The Foreman Bot 7 months ago

  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/4509 added

#4 Updated by Shimon Shtein 7 months ago

Thanks for finding the older issue - it's the same functionality I am talking about.
I think we can close the older one - this one is more informative.

This issue is about adding a generator to our framework, so the scope would be handled automatically for new migrations.

For example, by running the following command from foreman directory:

rails g plugin:migration test_migration --plugin-name=my_plugin

will generate a new migration file called 20170101000_test_migration.my_plugin.rb in plugin's db/migrate directory.

#5 Updated by Dominic Cleal 7 months ago

  • Duplicated by Feature #16595: Add scoping to plugin migrations. added

#6 Updated by Dominic Cleal 7 months ago

I think we can close the older one - this one is more informative.

Done, please just do it next time.

#7 Updated by Ivan Necas 7 months ago

  • Target version set to Team Ivan Iteration 15

#8 Updated by Shimon Shtein 7 months ago

  • Tracker changed from Feature to Tracker
  • Status changed from Ready For Testing to Assigned

#9 Updated by Shimon Shtein 7 months ago

  • Blocked by Feature #19589: Add an option to create plugin migrations with properly marked scope added

#10 Updated by Shimon Shtein 7 months ago

Changed this issue to track all the progress of marking migrations.
The work on core generator will be attached to http://projects.theforeman.org/issues/19589.

Also available in: Atom PDF