Skip to content

A platform for community discussion. Free, open, simple.

FIX: Improve allowed_path column migration (#10321)

Krzysztof Kotlarek14003abc37e5
diff --git a/db/migrate/20200728000854_duplicate_allowed_paths_from_path_whitelist.rb b/db/migrate/20200728000854_duplicate_allowed_paths_from_path_whitelist.rb
new file mode 100644
index 00000000000..17dd89960e5
--- /dev/null
+++ b/db/migrate/20200728000854_duplicate_allowed_paths_from_path_whitelist.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class DuplicateAllowedPathsFromPathWhitelist < ActiveRecord::Migration[6.0]
+ def up
+ unless column_exists?(:embeddable_hosts, :allowed_paths)
+ add_column :embeddable_hosts, :allowed_paths, :string
+ end
+
+ if column_exists?(:embeddable_hosts, :path_whitelist)
+ Migration::ColumnDropper.mark_readonly('embeddable_hosts', 'path_whitelist')
+
+ if column_exists?(:embeddable_hosts, :allowed_paths)
+ DB.exec <<~SQL
+ UPDATE embeddable_hosts
+ SET allowed_paths = path_whitelist
+ SQL
+ end
+ end
+ end
+
+ def down
+ remove_column :embeddable_hosts, :allowed_paths
+ end
+end
diff --git a/db/post_migrate/20200629232159_rename_path_whitelist_to_allowed_paths.rb b/db/post_migrate/20200629232159_rename_path_whitelist_to_allowed_paths.rb
deleted file mode 100644
index 3e55cabe2db..00000000000
--- a/db/post_migrate/20200629232159_rename_path_whitelist_to_allowed_paths.rb
+++ /dev/null
@@ -1,7 +0,0 @@
-# frozen_string_literal: true
-
-class RenamePathWhitelistToAllowedPaths < ActiveRecord::Migration[6.0]
- def change
- rename_column :embeddable_hosts, :path_whitelist, :allowed_paths
- end
-end
diff --git a/db/post_migrate/20200728004302_drop_path_whitelist_from_embeddable_hosts.rb b/db/post_migrate/20200728004302_drop_path_whitelist_from_embeddable_hosts.rb
new file mode 100644
index 00000000000..56771b4c075
--- /dev/null
+++ b/db/post_migrate/20200728004302_drop_path_whitelist_from_embeddable_hosts.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+class DropPathWhitelistFromEmbeddableHosts < ActiveRecord::Migration[6.0]
+ DROPPED_COLUMNS ||= {
+ embeddable_hosts: %i{path_whitelist}
+ }
+
+ def up
+ DROPPED_COLUMNS.each do |table, columns|
+ Migration::ColumnDropper.execute_drop(table, columns)
+ end
+ end
+
+ def down
+ add_column :embeddable_hosts, :path_whitelist, :string
+ end
+end