Commit fe74f803 authored by James Lopez's avatar James Lopez

Merge branch '208429-add-delete-status' into 'master'

Add status column to container_registry

See merge request gitlab-org/gitlab!28682
parents 8a23aa58 1afc1574
...@@ -28,6 +28,7 @@ module Projects ...@@ -28,6 +28,7 @@ module Projects
end end
def destroy def destroy
image.delete_scheduled!
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
track_event(:delete_repository) track_event(:delete_repository)
......
...@@ -8,6 +8,8 @@ class ContainerRepository < ApplicationRecord ...@@ -8,6 +8,8 @@ class ContainerRepository < ApplicationRecord
validates :name, length: { minimum: 0, allow_nil: false } validates :name, length: { minimum: 0, allow_nil: false }
validates :name, uniqueness: { scope: :project_id } validates :name, uniqueness: { scope: :project_id }
enum status: { delete_scheduled: 0, delete_failed: 1 }
delegate :client, to: :registry delegate :client, to: :registry
scope :ordered, -> { order(:name) } scope :ordered, -> { order(:name) }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
class ContainerRepositoryEntity < Grape::Entity class ContainerRepositoryEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :id, :name, :path, :location, :created_at expose :id, :name, :path, :location, :created_at, :status
expose :tags_path do |repository| expose :tags_path do |repository|
project_registry_repository_tags_path(project, repository, format: :json) project_registry_repository_tags_path(project, repository, format: :json)
......
...@@ -8,7 +8,7 @@ module Projects ...@@ -8,7 +8,7 @@ module Projects
# Delete tags outside of the transaction to avoid hitting an idle-in-transaction timeout # Delete tags outside of the transaction to avoid hitting an idle-in-transaction timeout
container_repository.delete_tags! container_repository.delete_tags!
container_repository.destroy container_repository.delete_failed! unless container_repository.destroy
end end
end end
end end
......
---
title: Add status column to container_registry
merge_request: 28682
author:
type: changed
# frozen_string_literal: true
class AddDeleteStatusToContainerRepository < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
add_column(:container_repositories, :status, :integer, limit: 2)
end
def down
remove_column(:container_repositories, :status)
end
end
...@@ -1850,7 +1850,8 @@ CREATE TABLE public.container_repositories ( ...@@ -1850,7 +1850,8 @@ CREATE TABLE public.container_repositories (
project_id integer NOT NULL, project_id integer NOT NULL,
name character varying NOT NULL, name character varying NOT NULL,
created_at timestamp without time zone NOT NULL, created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL updated_at timestamp without time zone NOT NULL,
status smallint
); );
CREATE SEQUENCE public.container_repositories_id_seq CREATE SEQUENCE public.container_repositories_id_seq
...@@ -12935,6 +12936,7 @@ COPY "schema_migrations" (version) FROM STDIN; ...@@ -12935,6 +12936,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200330123739 20200330123739
20200330132913 20200330132913
20200331220930 20200331220930
20200402135250
20200403184110 20200403184110
20200403185127 20200403185127
20200403185422 20200403185422
......
...@@ -110,6 +110,7 @@ describe Projects::Registry::RepositoriesController do ...@@ -110,6 +110,7 @@ describe Projects::Registry::RepositoriesController do
delete_repository(repository) delete_repository(repository)
expect(repository.reload).to be_delete_scheduled
expect(response).to have_gitlab_http_status(:no_content) expect(response).to have_gitlab_http_status(:no_content)
end end
......
...@@ -32,6 +32,12 @@ ...@@ -32,6 +32,12 @@
"destroy_path": { "destroy_path": {
"type": "string" "type": "string"
}, },
"status": {
"oneOf": [
{ "type": "null" },
{ "type": "string", "enum": ["delete_scheduled", "delete_failed"] }
]
},
"tags": { "$ref": "tags.json" } "tags": { "$ref": "tags.json" }
}, },
"additionalProperties": false "additionalProperties": false
......
...@@ -36,6 +36,16 @@ describe Projects::ContainerRepository::DestroyService do ...@@ -36,6 +36,16 @@ describe Projects::ContainerRepository::DestroyService do
expect(repository).to receive(:delete_tags!).and_call_original expect(repository).to receive(:delete_tags!).and_call_original
expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1) expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1)
end end
context 'when destroy fails' do
it 'set delete_status' do
allow(repository).to receive(:destroy).and_return(false)
subject.execute(repository)
expect(repository).to be_delete_failed
end
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment