Merge branch '19269-all-users-writable'
[arvados.git] / services / api / db / migrate / 20140319160547_separate_repository_from_script_version.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class SeparateRepositoryFromScriptVersion < ActiveRecord::Migration[4.2]
6   include CurrentApiClient
7
8   def fixup pt
9     c = pt.components
10     c.each do |k, v|
11       commit_ish = v["script_version"]
12       if commit_ish.andand.index(':')
13         want_repo, commit_ish = commit_ish.split(':',2)
14         v[:repository] = want_repo
15         v[:script_version] = commit_ish
16       end
17     end
18     pt.save!
19   end
20
21   def up
22     act_as_system_user do
23       PipelineTemplate.all.each do |pt|
24         fixup pt
25       end
26       PipelineInstance.all.each do |pt|
27         fixup pt
28       end
29     end
30   end
31
32   def down
33     raise ActiveRecord::IrreversibleMigration
34   end
35 end