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

disallow null in project phases references

Ivan Kuchin2cc1bda43882
diff --git a/db/migrate/20250428135623_disallow_null_in_project_phases_references.rb b/db/migrate/20250428135623_disallow_null_in_project_phases_references.rb
new file mode 100644
index 00000000000..d48842bf713
--- /dev/null
+++ b/db/migrate/20250428135623_disallow_null_in_project_phases_references.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+class DisallowNullInProjectPhasesReferences < ActiveRecord::Migration[8.0]
+ def change
+ reversible do |direction|
+ direction.up do
+ execute <<-SQL.squish
+ DELETE FROM project_phases WHERE project_id IS NULL OR definition_id IS NULL
+ SQL
+ end
+ end
+
+ change_table(:project_phases, bulk: true) do |t|
+ t.change_null :project_id, false
+ t.change_null :definition_id, false
+ end
+ end
+end