We require plugin migrations to be named in the form
YYYYMMDDHHMMSS_plugin_#{plugin_name}_*.rb to avoid any class
name and filename collisions between plugins and core Puppet
Dashboard or between plugins and other plugins.We can't simply rename the migration as we copy it into place, since this would require modifying the file contents to match the new name, and down that road lies madness. Requiring module authors to adhere to this naming convention for their migrations is fairly low cost given the previously mentioned constraints. Reviewed-by: Jesse Wolfe <[email protected]> Signed-off-by: Jacob Helwig <[email protected]> --- Local-branch: tickets/next/7209-improve-handling-of-plugin-migrations lib/tasks/plugins.rake | 15 ++++++++------- 1 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/tasks/plugins.rake b/lib/tasks/plugins.rake index c0353c4..6e8efe5 100644 --- a/lib/tasks/plugins.rake +++ b/lib/tasks/plugins.rake @@ -9,15 +9,16 @@ namespace :puppet do unless File.exists?(plugin_dir) raise "Plugin #{plugin_name} not found in vendor/plugins." end + Dir.glob(File.join(plugin_dir, 'db', 'migrate', '*.rb')) do |source_file| - if File.basename(source_file) =~ /^([0-9]+)_(.*)$/ - timestamp, migration_name = $1, $2 - # Downcase and replace anything not lower case letter, number or - # underscore (ie -, $, ^, space, etc) with underscores - new_migration_name = "#{timestamp}_plugin__#{plugin_name}__#{migration_name}".downcase.gsub(/[^a-z0-9_]/, '_') - destination_file = "db/migrate/#{new_migration_name}" - FileUtils.cp source_file, destination_file + base_file_name = File.basename(source_file) + + unless base_file_name.match(/^\d{14}_plugin_#{plugin_name}_.+\.rb$/) + raise "Found a misnamed migration: #{source_file}\n" + + "Migrations for this plugin must be named in the form: YYYYMMDDHHMMSS_plugin_#{plugin_name}_*.rb" end + + FileUtils.cp source_file, "db/migrate/#{base_file_name}" end end -- 1.7.5 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
