Commit 1afc1574 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by James Lopez

Handle delete_status in container registry

- controller update
- entity update
- destroy_service update
parent 96df6dcd
......@@ -28,6 +28,7 @@ module Projects
end
def destroy
image.delete_scheduled!
DeleteContainerRepositoryWorker.perform_async(current_user.id, image.id) # rubocop:disable CodeReuse/Worker
track_event(:delete_repository)
......
......@@ -8,6 +8,8 @@ class ContainerRepository < ApplicationRecord
validates :name, length: { minimum: 0, allow_nil: false }
validates :name, uniqueness: { scope: :project_id }
enum status: { delete_scheduled: 0, delete_failed: 1 }
delegate :client, to: :registry
scope :ordered, -> { order(:name) }
......
......@@ -3,7 +3,7 @@
class ContainerRepositoryEntity < Grape::Entity
include RequestAwareEntity
expose :id, :name, :path, :location, :created_at
expose :id, :name, :path, :location, :created_at, :status
expose :tags_path do |repository|
project_registry_repository_tags_path(project, repository, format: :json)
......
......@@ -8,7 +8,7 @@ module Projects
# Delete tags outside of the transaction to avoid hitting an idle-in-transaction timeout
container_repository.delete_tags!
container_repository.destroy
container_repository.delete_failed! unless container_repository.destroy
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 (
project_id integer NOT NULL,
name character varying 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
......@@ -12935,6 +12936,7 @@ COPY "schema_migrations" (version) FROM STDIN;
20200330123739
20200330132913
20200331220930
20200402135250
20200403184110
20200403185127
20200403185422
......
......@@ -110,6 +110,7 @@ describe Projects::Registry::RepositoriesController do
delete_repository(repository)
expect(repository.reload).to be_delete_scheduled
expect(response).to have_gitlab_http_status(:no_content)
end
......
......@@ -32,6 +32,12 @@
"destroy_path": {
"type": "string"
},
"status": {
"oneOf": [
{ "type": "null" },
{ "type": "string", "enum": ["delete_scheduled", "delete_failed"] }
]
},
"tags": { "$ref": "tags.json" }
},
"additionalProperties": false
......
......@@ -36,6 +36,16 @@ describe Projects::ContainerRepository::DestroyService do
expect(repository).to receive(:delete_tags!).and_call_original
expect { described_class.new(project, user).execute(repository) }.to change { ContainerRepository.all.count }.by(-1)
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
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