Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Do not use Storages::Storage model in migrations.

Pavel Balashoue5c00bdb01c3
diff --git a/modules/storages/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb b/modules/storages/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb
index d76f7b7922f..0b5ec2ebbc7 100644
--- a/modules/storages/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb
+++ b/modules/storages/db/migrate/20230420071113_migrate_storages_to_use_provider_type_as_sti_column.rb
@@ -27,14 +27,14 @@
class MigrateStoragesToUseProviderTypeAsStiColumn < ActiveRecord::Migration[7.0]
def up
- Storages::Storage
- .where(provider_type: 'nextcloud')
- .update_all("provider_type = 'Storages::NextcloudStorage'")
+ execute <<~SQL
+ UPDATE "storages" SET provider_type = 'Storages::NextcloudStorage' WHERE "storages"."provider_type" = 'nextcloud'
+ SQL
end
def down
- Storages::Storage
- .where(provider_type: 'Storages::NextcloudStorage')
- .update_all("provider_type = 'nextcloud'")
+ execute <<~SQL
+ UPDATE "storages" SET provider_type = 'nextcloud' WHERE "storages"."provider_type" = 'Storages::NextcloudStorage'
+ SQL
end
end
diff --git a/modules/storages/db/migrate/20230512153303_change_storage_provider_fields_default.rb b/modules/storages/db/migrate/20230512153303_change_storage_provider_fields_default.rb
index ed017385543..a97d63b244b 100644
--- a/modules/storages/db/migrate/20230512153303_change_storage_provider_fields_default.rb
+++ b/modules/storages/db/migrate/20230512153303_change_storage_provider_fields_default.rb
@@ -31,7 +31,11 @@ class ChangeStorageProviderFieldsDefault < ActiveRecord::Migration[7.0]
reversible do |dir|
dir.up do
- Storages::Storage.where(provider_fields: '{}').update_all(provider_fields: {})
+ execute <<~SQL
+ UPDATE "storages"
+ SET "provider_fields" = '{}'
+ WHERE "storages"."provider_fields" = '"{}"'
+ SQL
end
end
end
diff --git a/modules/storages/db/migrate/20230824130730_remove_not_null_constraint_for_storage_host.rb b/modules/storages/db/migrate/20230824130730_remove_not_null_constraint_for_storage_host.rb
index 85028fe07b9..440149dddea 100644
--- a/modules/storages/db/migrate/20230824130730_remove_not_null_constraint_for_storage_host.rb
+++ b/modules/storages/db/migrate/20230824130730_remove_not_null_constraint_for_storage_host.rb
@@ -1,3 +1,31 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
class RemoveNotNullConstraintForStorageHost < ActiveRecord::Migration[7.0]
def up
change_column :storages, :host, :string, null: true
@@ -5,7 +33,7 @@ class RemoveNotNullConstraintForStorageHost < ActiveRecord::Migration[7.0]
end
def down
- ::Storages::Storage.where(host: nil).delete_all
+ execute 'DELETE FROM "storages" WHERE "storages"."host" IS NULL'
change_column :storages, :host, :string, null: false
::OAuthClient.where(client_secret: nil).delete_all
diff --git a/modules/storages/db/migrate/20231109080454_add_health_info_to_storages.rb b/modules/storages/db/migrate/20231109080454_add_health_info_to_storages.rb
index f2cb2c76ca5..a52b02f107a 100644
--- a/modules/storages/db/migrate/20231109080454_add_health_info_to_storages.rb
+++ b/modules/storages/db/migrate/20231109080454_add_health_info_to_storages.rb
@@ -1,3 +1,30 @@
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See COPYRIGHT and LICENSE files for more details.
+#++
+
class AddHealthInfoToStorages < ActiveRecord::Migration[7.0]
def change
add_column :storages, :health_info, :jsonb, null: false, default: {}