Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2de24b79
Commit
2de24b79
authored
Oct 30, 2019
by
Gosia Ksionek
Committed by
Imre Farkas
Oct 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve "Preventing accidental project deletion" - db changes
parent
79038226
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
118 additions
and
0 deletions
+118
-0
changelogs/unreleased/32935-preventing-accidental-project-deletion-db-changes.yml
...935-preventing-accidental-project-deletion-db-changes.yml
+5
-0
db/migrate/20191003161031_add_mark_for_deletion_to_projects.rb
...grate/20191003161031_add_mark_for_deletion_to_projects.rb
+11
-0
db/migrate/20191003161032_add_mark_for_deletion_indexes_to_projects.rb
...191003161032_add_mark_for_deletion_indexes_to_projects.rb
+19
-0
db/migrate/20191011084019_add_project_deletion_adjourned_period_to_application_settings.rb
...ject_deletion_adjourned_period_to_application_settings.rb
+11
-0
db/schema.rb
db/schema.rb
+5
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+13
-0
ee/app/models/license.rb
ee/app/models/license.rb
+1
-0
ee/spec/models/project_spec.rb
ee/spec/models/project_spec.rb
+50
-0
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+2
-0
spec/lib/gitlab/import_export/all_models.yml
spec/lib/gitlab/import_export/all_models.yml
+1
-0
No files found.
changelogs/unreleased/32935-preventing-accidental-project-deletion-db-changes.yml
0 → 100644
View file @
2de24b79
---
title
:
Add migrations and changes for soft-delete for projects
merge_request
:
18791
author
:
type
:
added
db/migrate/20191003161031_add_mark_for_deletion_to_projects.rb
0 → 100644
View file @
2de24b79
# frozen_string_literal: true
class
AddMarkForDeletionToProjects
<
ActiveRecord
::
Migration
[
5.2
]
# Set this constant to true if this migration requires downtime.
DOWNTIME
=
false
def
change
add_column
:projects
,
:marked_for_deletion_at
,
:date
add_column
:projects
,
:marked_for_deletion_by_user_id
,
:integer
end
end
db/migrate/20191003161032_add_mark_for_deletion_indexes_to_projects.rb
0 → 100644
View file @
2de24b79
# frozen_string_literal: true
class
AddMarkForDeletionIndexesToProjects
<
ActiveRecord
::
Migration
[
5.2
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_foreign_key
:projects
,
:users
,
column: :marked_for_deletion_by_user_id
,
on_delete: :nullify
add_concurrent_index
:projects
,
:marked_for_deletion_by_user_id
,
where:
'marked_for_deletion_by_user_id IS NOT NULL'
end
def
down
remove_foreign_key_if_exists
:projects
,
column: :marked_for_deletion_by_user_id
remove_concurrent_index
:projects
,
:marked_for_deletion_by_user_id
end
end
db/migrate/20191011084019_add_project_deletion_adjourned_period_to_application_settings.rb
0 → 100644
View file @
2de24b79
# frozen_string_literal: true
class
AddProjectDeletionAdjournedPeriodToApplicationSettings
<
ActiveRecord
::
Migration
[
5.2
]
DOWNTIME
=
false
DEFAULT_NUMBER_OF_DAYS_BEFORE_REMOVAL
=
7
def
change
add_column
:application_settings
,
:deletion_adjourned_period
,
:integer
,
default:
DEFAULT_NUMBER_OF_DAYS_BEFORE_REMOVAL
,
null:
false
end
end
db/schema.rb
View file @
2de24b79
...
@@ -343,6 +343,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
...
@@ -343,6 +343,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
t
.
string
"custom_http_clone_url_root"
,
limit:
511
t
.
string
"custom_http_clone_url_root"
,
limit:
511
t
.
boolean
"pendo_enabled"
,
default:
false
,
null:
false
t
.
boolean
"pendo_enabled"
,
default:
false
,
null:
false
t
.
string
"pendo_url"
,
limit:
255
t
.
string
"pendo_url"
,
limit:
255
t
.
integer
"deletion_adjourned_period"
,
default:
7
,
null:
false
t
.
index
[
"custom_project_templates_group_id"
],
name:
"index_application_settings_on_custom_project_templates_group_id"
t
.
index
[
"custom_project_templates_group_id"
],
name:
"index_application_settings_on_custom_project_templates_group_id"
t
.
index
[
"file_template_project_id"
],
name:
"index_application_settings_on_file_template_project_id"
t
.
index
[
"file_template_project_id"
],
name:
"index_application_settings_on_file_template_project_id"
t
.
index
[
"instance_administration_project_id"
],
name:
"index_applicationsettings_on_instance_administration_project_id"
t
.
index
[
"instance_administration_project_id"
],
name:
"index_applicationsettings_on_instance_administration_project_id"
...
@@ -3073,6 +3074,8 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
...
@@ -3073,6 +3074,8 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
t
.
integer
"max_artifacts_size"
t
.
integer
"max_artifacts_size"
t
.
string
"pull_mirror_branch_prefix"
,
limit:
50
t
.
string
"pull_mirror_branch_prefix"
,
limit:
50
t
.
boolean
"remove_source_branch_after_merge"
t
.
boolean
"remove_source_branch_after_merge"
t
.
date
"marked_for_deletion_at"
t
.
integer
"marked_for_deletion_by_user_id"
t
.
index
"lower((name)::text)"
,
name:
"index_projects_on_lower_name"
t
.
index
"lower((name)::text)"
,
name:
"index_projects_on_lower_name"
t
.
index
[
"archived"
,
"pending_delete"
,
"merge_requests_require_code_owner_approval"
],
name:
"projects_requiring_code_owner_approval"
,
where:
"((pending_delete = false) AND (archived = false) AND (merge_requests_require_code_owner_approval = true))"
t
.
index
[
"archived"
,
"pending_delete"
,
"merge_requests_require_code_owner_approval"
],
name:
"projects_requiring_code_owner_approval"
,
where:
"((pending_delete = false) AND (archived = false) AND (merge_requests_require_code_owner_approval = true))"
t
.
index
[
"created_at"
],
name:
"index_projects_on_created_at"
t
.
index
[
"created_at"
],
name:
"index_projects_on_created_at"
...
@@ -3085,6 +3088,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
...
@@ -3085,6 +3088,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
t
.
index
[
"last_repository_check_at"
],
name:
"index_projects_on_last_repository_check_at"
,
where:
"(last_repository_check_at IS NOT NULL)"
t
.
index
[
"last_repository_check_at"
],
name:
"index_projects_on_last_repository_check_at"
,
where:
"(last_repository_check_at IS NOT NULL)"
t
.
index
[
"last_repository_check_failed"
],
name:
"index_projects_on_last_repository_check_failed"
t
.
index
[
"last_repository_check_failed"
],
name:
"index_projects_on_last_repository_check_failed"
t
.
index
[
"last_repository_updated_at"
],
name:
"index_projects_on_last_repository_updated_at"
t
.
index
[
"last_repository_updated_at"
],
name:
"index_projects_on_last_repository_updated_at"
t
.
index
[
"marked_for_deletion_by_user_id"
],
name:
"index_projects_on_marked_for_deletion_by_user_id"
,
where:
"(marked_for_deletion_by_user_id IS NOT NULL)"
t
.
index
[
"mirror_last_successful_update_at"
],
name:
"index_projects_on_mirror_last_successful_update_at"
t
.
index
[
"mirror_last_successful_update_at"
],
name:
"index_projects_on_mirror_last_successful_update_at"
t
.
index
[
"mirror_user_id"
],
name:
"index_projects_on_mirror_user_id"
t
.
index
[
"mirror_user_id"
],
name:
"index_projects_on_mirror_user_id"
t
.
index
[
"name"
],
name:
"index_projects_on_name_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
t
.
index
[
"name"
],
name:
"index_projects_on_name_trigram"
,
opclass: :gin_trgm_ops
,
using: :gin
...
@@ -4356,6 +4360,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
...
@@ -4356,6 +4360,7 @@ ActiveRecord::Schema.define(version: 2019_10_26_124116) do
add_foreign_key
"project_statistics"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"project_statistics"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"project_tracing_settings"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"project_tracing_settings"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"projects"
,
"pool_repositories"
,
name:
"fk_6e5c14658a"
,
on_delete: :nullify
add_foreign_key
"projects"
,
"pool_repositories"
,
name:
"fk_6e5c14658a"
,
on_delete: :nullify
add_foreign_key
"projects"
,
"users"
,
column:
"marked_for_deletion_by_user_id"
,
name:
"fk_25d8780d11"
,
on_delete: :nullify
add_foreign_key
"prometheus_alert_events"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"prometheus_alert_events"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"prometheus_alert_events"
,
"prometheus_alerts"
,
on_delete: :cascade
add_foreign_key
"prometheus_alert_events"
,
"prometheus_alerts"
,
on_delete: :cascade
add_foreign_key
"prometheus_alerts"
,
"environments"
,
on_delete: :cascade
add_foreign_key
"prometheus_alerts"
,
"environments"
,
on_delete: :cascade
...
...
ee/app/models/ee/project.rb
View file @
2de24b79
...
@@ -35,6 +35,7 @@ module EE
...
@@ -35,6 +35,7 @@ module EE
if:
->
(
project
)
{
project
.
mirror?
&&
project
.
import_url_updated?
}
if:
->
(
project
)
{
project
.
mirror?
&&
project
.
import_url_updated?
}
belongs_to
:mirror_user
,
foreign_key:
'mirror_user_id'
,
class_name:
'User'
belongs_to
:mirror_user
,
foreign_key:
'mirror_user_id'
,
class_name:
'User'
belongs_to
:deleting_user
,
foreign_key:
'marked_for_deletion_by_user_id'
,
class_name:
'User'
has_one
:repository_state
,
class_name:
'ProjectRepositoryState'
,
inverse_of: :project
has_one
:repository_state
,
class_name:
'ProjectRepositoryState'
,
inverse_of: :project
has_one
:project_registry
,
class_name:
'Geo::ProjectRegistry'
,
inverse_of: :project
has_one
:project_registry
,
class_name:
'Geo::ProjectRegistry'
,
inverse_of: :project
...
@@ -132,6 +133,7 @@ module EE
...
@@ -132,6 +133,7 @@ module EE
scope
:with_slack_service
,
->
{
joins
(
:slack_service
)
}
scope
:with_slack_service
,
->
{
joins
(
:slack_service
)
}
scope
:with_slack_slash_commands_service
,
->
{
joins
(
:slack_slash_commands_service
)
}
scope
:with_slack_slash_commands_service
,
->
{
joins
(
:slack_slash_commands_service
)
}
scope
:with_prometheus_service
,
->
{
joins
(
:prometheus_service
)
}
scope
:with_prometheus_service
,
->
{
joins
(
:prometheus_service
)
}
scope
:aimed_for_deletion
,
->
(
date
)
{
where
(
'marked_for_deletion_at <= ?'
,
date
).
without_deleted
}
delegate
:shared_runners_minutes
,
:shared_runners_seconds
,
:shared_runners_seconds_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_seconds
,
:shared_runners_seconds_last_reset
,
to: :statistics
,
allow_nil:
true
to: :statistics
,
allow_nil:
true
...
@@ -655,6 +657,17 @@ module EE
...
@@ -655,6 +657,17 @@ module EE
.
exists?
.
exists?
end
end
def
adjourned_deletion?
feature_available?
(
:marking_project_for_deletion
)
&&
::
Gitlab
::
CurrentSettings
.
deletion_adjourned_period
>
0
end
def
marked_for_deletion?
return
false
unless
feature_available?
(
:marking_project_for_deletion
)
marked_for_deletion_at
.
present?
end
private
private
def
set_override_pull_mirror_available
def
set_override_pull_mirror_available
...
...
ee/app/models/license.rb
View file @
2de24b79
...
@@ -75,6 +75,7 @@ class License < ApplicationRecord
...
@@ -75,6 +75,7 @@ class License < ApplicationRecord
issues_analytics
issues_analytics
jira_dev_panel_integration
jira_dev_panel_integration
ldap_group_sync_filter
ldap_group_sync_filter
marking_project_for_deletion
merge_pipelines
merge_pipelines
merge_request_performance_metrics
merge_request_performance_metrics
merge_trains
merge_trains
...
...
ee/spec/models/project_spec.rb
View file @
2de24b79
...
@@ -22,6 +22,8 @@ describe Project do
...
@@ -22,6 +22,8 @@ describe Project do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_used?
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_used?
).
to
(
:shared_runners_limit_namespace
)
}
it
{
is_expected
.
to
belong_to
(
:deleting_user
)
}
it
{
is_expected
.
to
have_one
(
:import_state
).
class_name
(
'ProjectImportState'
)
}
it
{
is_expected
.
to
have_one
(
:import_state
).
class_name
(
'ProjectImportState'
)
}
it
{
is_expected
.
to
have_one
(
:repository_state
).
class_name
(
'ProjectRepositoryState'
).
inverse_of
(
:project
)
}
it
{
is_expected
.
to
have_one
(
:repository_state
).
class_name
(
'ProjectRepositoryState'
).
inverse_of
(
:project
)
}
it
{
is_expected
.
to
have_one
(
:alerting_setting
).
class_name
(
'Alerting::ProjectAlertingSetting'
)
}
it
{
is_expected
.
to
have_one
(
:alerting_setting
).
class_name
(
'Alerting::ProjectAlertingSetting'
)
}
...
@@ -2213,4 +2215,52 @@ describe Project do
...
@@ -2213,4 +2215,52 @@ describe Project do
end
end
end
end
end
end
describe
'#adjourned_deletion?'
do
context
'when marking for deletion feature is available'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
stub_licensed_features
(
marking_project_for_deletion:
true
)
end
context
'when number of days is set to more than 0'
do
it
'returns true'
do
stub_application_setting
(
deletion_adjourned_period:
1
)
expect
(
project
.
adjourned_deletion?
).
to
eq
(
true
)
end
end
context
'when number of days is set to 0'
do
it
'returns false'
do
stub_application_setting
(
deletion_adjourned_period:
0
)
expect
(
project
.
adjourned_deletion?
).
to
eq
(
false
)
end
end
end
context
'when marking for deletion feature is not available'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
stub_licensed_features
(
marking_project_for_deletion:
false
)
end
context
'when number of days is set to more than 0'
do
it
'returns false'
do
stub_application_setting
(
deletion_adjourned_period:
1
)
expect
(
project
.
adjourned_deletion?
).
to
eq
(
false
)
end
end
context
'when number of days is set to 0'
do
it
'returns false'
do
stub_application_setting
(
deletion_adjourned_period:
0
)
expect
(
project
.
adjourned_deletion?
).
to
eq
(
false
)
end
end
end
end
end
end
lib/gitlab/import_export/import_export.yml
View file @
2de24b79
...
@@ -148,6 +148,8 @@ excluded_attributes:
...
@@ -148,6 +148,8 @@ excluded_attributes:
-
:emails_disabled
-
:emails_disabled
-
:max_pages_size
-
:max_pages_size
-
:max_artifacts_size
-
:max_artifacts_size
-
:marked_for_deletion_at
-
:marked_for_deletion_by_user_id
namespaces
:
namespaces
:
-
:runners_token
-
:runners_token
-
:runners_token_encrypted
-
:runners_token_encrypted
...
...
spec/lib/gitlab/import_export/all_models.yml
View file @
2de24b79
...
@@ -423,6 +423,7 @@ project:
...
@@ -423,6 +423,7 @@ project:
-
alerts_service
-
alerts_service
-
grafana_integration
-
grafana_integration
-
remove_source_branch_after_merge
-
remove_source_branch_after_merge
-
deleting_user
award_emoji
:
award_emoji
:
-
awardable
-
awardable
-
user
-
user
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment