Files
ubicloud/model/github/github_cache_entry.rb
Jeremy Evans 30247a3800 Include model annotations at the bottom of all model files
This makes it easier for developers new to the codebase to
easily get important information on the model's table in the
same file as the model code.

To ensure the model annotations stay accurate, run them on
test_up/test_down.  In CI, regenerate the annotations, and
check for no changes, similar to how the linters work.
2024-11-13 09:13:30 -08:00

56 lines
1.8 KiB
Ruby

# frozen_string_literal: true
require_relative "../../model"
require "aws-sdk-s3"
class GithubCacheEntry < Sequel::Model
many_to_one :repository, key: :repository_id, class: :GithubRepository
include ResourceMethods
def self.ubid_type
UBID::TYPE_ETC
end
def blob_key
"cache/#{ubid}"
end
def after_destroy
super
if committed_at.nil?
begin
repository.blob_storage_client.abort_multipart_upload(bucket: repository.bucket_name, key: blob_key, upload_id: upload_id)
rescue Aws::S3::Errors::NoSuchUpload
end
end
begin
repository.blob_storage_client.delete_object(bucket: repository.bucket_name, key: blob_key)
rescue Aws::S3::Errors::NoSuchKey
end
end
end
# Table: github_cache_entry
# Columns:
# id | uuid | PRIMARY KEY
# repository_id | uuid | NOT NULL
# key | text | NOT NULL
# version | text | NOT NULL
# scope | text | NOT NULL
# size | bigint |
# upload_id | text |
# created_at | timestamp with time zone | NOT NULL DEFAULT now()
# created_by | uuid | NOT NULL
# last_accessed_at | timestamp with time zone |
# last_accessed_by | uuid |
# committed_at | timestamp with time zone |
# Indexes:
# github_cache_entry_pkey | PRIMARY KEY btree (id)
# github_cache_entry_repository_id_scope_key_version_key | UNIQUE btree (repository_id, scope, key, version)
# github_cache_entry_upload_id_key | UNIQUE btree (upload_id)
# Foreign key constraints:
# github_cache_entry_repository_id_fkey | (repository_id) REFERENCES github_repository(id)