summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-08 01:13:50 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-03-08 01:23:19 -0300
commit1fc9953c81af35b80b91ed0f0d6eb7b6f3625871 (patch)
treeec434b0fda4b2995c336c99566917e4007510e38
parent2db00dd5e0384cb5fb1d22864261283dd779a19f (diff)
downloadgitlab-ce-destroy-related-todos-when-removing-project.tar.gz
Destroy all related todos when removing a projectdestroy-related-todos-when-removing-project
-rw-r--r--CHANGELOG3
-rw-r--r--app/models/project.rb1
-rw-r--r--db/migrate/20160308040034_fix_todos.rb15
-rw-r--r--db/schema.rb2
-rw-r--r--spec/models/project_spec.rb1
5 files changed, 21 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a8dc00ed814..060965e0a14 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -16,6 +16,9 @@ v 8.6.0 (unreleased)
- Increase the notes polling timeout over time (Roberto Dip)
- Show labels in dashboard and group milestone views
+v 8.5.5
+ - Fix: Destroy all related todos when removing a project
+
v 8.5.4
- Do not cache requests for badges (including builds badge)
diff --git a/app/models/project.rb b/app/models/project.rb
index 3235a1cee50..426464dee81 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -151,6 +151,7 @@ class Project < ActiveRecord::Base
has_many :releases, dependent: :destroy
has_many :lfs_objects_projects, dependent: :destroy
has_many :lfs_objects, through: :lfs_objects_projects
+ has_many :todos, dependent: :destroy
has_one :import_data, dependent: :destroy, class_name: "ProjectImportData"
diff --git a/db/migrate/20160308040034_fix_todos.rb b/db/migrate/20160308040034_fix_todos.rb
new file mode 100644
index 00000000000..3a2979229cd
--- /dev/null
+++ b/db/migrate/20160308040034_fix_todos.rb
@@ -0,0 +1,15 @@
+class FixTodos < ActiveRecord::Migration
+ def up
+ execute <<-SQL
+ DELETE FROM todos
+ WHERE NOT EXISTS (
+ SELECT *
+ FROM projects
+ WHERE projects.id = todos.id
+ )
+ SQL
+ end
+
+ def down
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 71d9257a31e..e82b58757a8 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20160222153918) do
+ActiveRecord::Schema.define(version: 20160308040034) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index f9842d23afa..012be3e2dfc 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -68,6 +68,7 @@ describe Project, models: true do
it { is_expected.to have_many(:runners) }
it { is_expected.to have_many(:variables) }
it { is_expected.to have_many(:triggers) }
+ it { is_expected.to have_many(:todos).dependent(:destroy) }
end
describe 'modules' do