|
|
|
@@ -56,7 +56,97 @@ OPTIONS |
|
|
|
) |
|
|
|
; |
|
|
|
delete from public.repository_es; |
|
|
|
INSERT INTO public.repository_es (id, |
|
|
|
INSERT INTO public.repository_es (id, |
|
|
|
owner_id, |
|
|
|
owner_name, |
|
|
|
lower_name, |
|
|
|
name, |
|
|
|
description, |
|
|
|
website, |
|
|
|
original_service_type, |
|
|
|
original_url, |
|
|
|
default_branch, |
|
|
|
num_watches, |
|
|
|
num_stars, |
|
|
|
num_forks, |
|
|
|
num_issues, |
|
|
|
num_closed_issues, |
|
|
|
num_pulls, |
|
|
|
num_closed_pulls, |
|
|
|
num_milestones, |
|
|
|
num_closed_milestones, |
|
|
|
is_private, |
|
|
|
is_empty, |
|
|
|
is_archived, |
|
|
|
is_mirror, |
|
|
|
status, |
|
|
|
is_fork, |
|
|
|
fork_id, |
|
|
|
is_template, |
|
|
|
template_id, |
|
|
|
size, |
|
|
|
is_fsck_enabled, |
|
|
|
close_issues_via_commit_in_any_branch, |
|
|
|
topics, |
|
|
|
avatar, |
|
|
|
created_unix, |
|
|
|
updated_unix, |
|
|
|
contract_address, |
|
|
|
block_chain_status, |
|
|
|
balance, |
|
|
|
clone_cnt, |
|
|
|
num_commit, |
|
|
|
git_clone_cnt,lang) |
|
|
|
SELECT |
|
|
|
id, |
|
|
|
owner_id, |
|
|
|
owner_name, |
|
|
|
lower_name, |
|
|
|
name, |
|
|
|
description, |
|
|
|
website, |
|
|
|
original_service_type, |
|
|
|
original_url, |
|
|
|
default_branch, |
|
|
|
num_watches, |
|
|
|
num_stars, |
|
|
|
num_forks, |
|
|
|
num_issues, |
|
|
|
num_closed_issues, |
|
|
|
num_pulls, |
|
|
|
num_closed_pulls, |
|
|
|
num_milestones, |
|
|
|
num_closed_milestones, |
|
|
|
is_private, |
|
|
|
is_empty, |
|
|
|
is_archived, |
|
|
|
is_mirror, |
|
|
|
status, |
|
|
|
is_fork, |
|
|
|
fork_id, |
|
|
|
is_template, |
|
|
|
template_id, |
|
|
|
size, |
|
|
|
is_fsck_enabled, |
|
|
|
close_issues_via_commit_in_any_branch, |
|
|
|
topics, |
|
|
|
avatar, |
|
|
|
created_unix, |
|
|
|
updated_unix, |
|
|
|
contract_address, |
|
|
|
block_chain_status, |
|
|
|
balance, |
|
|
|
clone_cnt, |
|
|
|
num_commit, |
|
|
|
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id) |
|
|
|
FROM public.repository b where b.is_private=false; |
|
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION public.insert_repository_data() RETURNS trigger AS |
|
|
|
$def$ |
|
|
|
BEGIN |
|
|
|
if not NEW.is_private then |
|
|
|
INSERT INTO public.repository_es (id, |
|
|
|
owner_id, |
|
|
|
owner_name, |
|
|
|
lower_name, |
|
|
|
@@ -96,9 +186,70 @@ INSERT INTO public.repository_es (id, |
|
|
|
balance, |
|
|
|
clone_cnt, |
|
|
|
num_commit, |
|
|
|
git_clone_cnt,lang) |
|
|
|
SELECT |
|
|
|
id, |
|
|
|
git_clone_cnt) VALUES |
|
|
|
(NEW.id, |
|
|
|
NEW.owner_id, |
|
|
|
NEW.owner_name, |
|
|
|
NEW.lower_name, |
|
|
|
NEW.name, |
|
|
|
NEW.description, |
|
|
|
NEW.website, |
|
|
|
NEW.original_service_type, |
|
|
|
NEW.original_url, |
|
|
|
NEW.default_branch, |
|
|
|
NEW.num_watches, |
|
|
|
NEW.num_stars, |
|
|
|
NEW.num_forks, |
|
|
|
NEW.num_issues, |
|
|
|
NEW.num_closed_issues, |
|
|
|
NEW.num_pulls, |
|
|
|
NEW.num_closed_pulls, |
|
|
|
NEW.num_milestones, |
|
|
|
NEW.num_closed_milestones, |
|
|
|
NEW.is_private, |
|
|
|
NEW.is_empty, |
|
|
|
NEW.is_archived, |
|
|
|
NEW.is_mirror, |
|
|
|
NEW.status, |
|
|
|
NEW.is_fork, |
|
|
|
NEW.fork_id, |
|
|
|
NEW.is_template, |
|
|
|
NEW.template_id, |
|
|
|
NEW.size, |
|
|
|
NEW.is_fsck_enabled, |
|
|
|
NEW.close_issues_via_commit_in_any_branch, |
|
|
|
NEW.topics, |
|
|
|
NEW.avatar, |
|
|
|
NEW.created_unix, |
|
|
|
NEW.updated_unix, |
|
|
|
NEW.contract_address, |
|
|
|
NEW.block_chain_status, |
|
|
|
NEW.balance, |
|
|
|
NEW.clone_cnt, |
|
|
|
NEW.num_commit, |
|
|
|
NEW.git_clone_cnt); |
|
|
|
end if; |
|
|
|
RETURN NEW; |
|
|
|
END; |
|
|
|
$def$ |
|
|
|
LANGUAGE plpgsql; |
|
|
|
|
|
|
|
DROP TRIGGER IF EXISTS es_insert_repository on public.repository; |
|
|
|
|
|
|
|
|
|
|
|
CREATE TRIGGER es_insert_repository |
|
|
|
AFTER INSERT ON public.repository |
|
|
|
FOR EACH ROW EXECUTE PROCEDURE insert_repository_data(); |
|
|
|
|
|
|
|
ALTER TABLE public.repository ENABLE ALWAYS TRIGGER es_insert_repository; |
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION public.update_repository() RETURNS trigger AS |
|
|
|
$def$ |
|
|
|
BEGIN |
|
|
|
if OLD.is_private != NEW.is_private then |
|
|
|
if OLD.is_private and not NEW.is_private then |
|
|
|
--insert |
|
|
|
INSERT INTO public.repository_es (id, |
|
|
|
owner_id, |
|
|
|
owner_name, |
|
|
|
lower_name, |
|
|
|
@@ -138,15 +289,9 @@ INSERT INTO public.repository_es (id, |
|
|
|
balance, |
|
|
|
clone_cnt, |
|
|
|
num_commit, |
|
|
|
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id) |
|
|
|
FROM public.repository b where b.is_private=false; |
|
|
|
|
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION public.insert_repository_data() RETURNS trigger AS |
|
|
|
$def$ |
|
|
|
BEGIN |
|
|
|
if not NEW.is_private then |
|
|
|
INSERT INTO public.repository_es (id, |
|
|
|
git_clone_cnt,lang) |
|
|
|
SELECT |
|
|
|
id, |
|
|
|
owner_id, |
|
|
|
owner_name, |
|
|
|
lower_name, |
|
|
|
@@ -186,86 +331,152 @@ $def$ |
|
|
|
balance, |
|
|
|
clone_cnt, |
|
|
|
num_commit, |
|
|
|
git_clone_cnt) VALUES |
|
|
|
(NEW.id, |
|
|
|
NEW.owner_id, |
|
|
|
NEW.owner_name, |
|
|
|
NEW.lower_name, |
|
|
|
NEW.name, |
|
|
|
NEW.description, |
|
|
|
NEW.website, |
|
|
|
NEW.original_service_type, |
|
|
|
NEW.original_url, |
|
|
|
NEW.default_branch, |
|
|
|
NEW.num_watches, |
|
|
|
NEW.num_stars, |
|
|
|
NEW.num_forks, |
|
|
|
NEW.num_issues, |
|
|
|
NEW.num_closed_issues, |
|
|
|
NEW.num_pulls, |
|
|
|
NEW.num_closed_pulls, |
|
|
|
NEW.num_milestones, |
|
|
|
NEW.num_closed_milestones, |
|
|
|
NEW.is_private, |
|
|
|
NEW.is_empty, |
|
|
|
NEW.is_archived, |
|
|
|
NEW.is_mirror, |
|
|
|
NEW.status, |
|
|
|
NEW.is_fork, |
|
|
|
NEW.fork_id, |
|
|
|
NEW.is_template, |
|
|
|
NEW.template_id, |
|
|
|
NEW.size, |
|
|
|
NEW.is_fsck_enabled, |
|
|
|
NEW.close_issues_via_commit_in_any_branch, |
|
|
|
NEW.topics, |
|
|
|
NEW.avatar, |
|
|
|
NEW.created_unix, |
|
|
|
NEW.updated_unix, |
|
|
|
NEW.contract_address, |
|
|
|
NEW.block_chain_status, |
|
|
|
NEW.balance, |
|
|
|
NEW.clone_cnt, |
|
|
|
NEW.num_commit, |
|
|
|
NEW.git_clone_cnt); |
|
|
|
end if; |
|
|
|
RETURN NEW; |
|
|
|
END; |
|
|
|
$def$ |
|
|
|
LANGUAGE plpgsql; |
|
|
|
|
|
|
|
DROP TRIGGER IF EXISTS es_insert_repository on public.repository; |
|
|
|
|
|
|
|
|
|
|
|
CREATE TRIGGER es_insert_repository |
|
|
|
AFTER INSERT ON public.repository |
|
|
|
FOR EACH ROW EXECUTE PROCEDURE insert_repository_data(); |
|
|
|
|
|
|
|
ALTER TABLE public.repository ENABLE ALWAYS TRIGGER es_insert_repository; |
|
|
|
git_clone_cnt,(select string_agg(language, ',') from public.language_stat a where a.repo_id=b.id) |
|
|
|
FROM public.repository b where b.id=NEW.id; |
|
|
|
INSERT INTO public.dataset_es( |
|
|
|
id, |
|
|
|
title, |
|
|
|
status, |
|
|
|
category, |
|
|
|
description, |
|
|
|
download_times, |
|
|
|
license, task, |
|
|
|
release_id, |
|
|
|
user_id, |
|
|
|
repo_id, |
|
|
|
created_unix, |
|
|
|
updated_unix,file_name) |
|
|
|
SELECT |
|
|
|
b.id, |
|
|
|
b.title, |
|
|
|
b.status, |
|
|
|
b.category, |
|
|
|
b.description, |
|
|
|
b.download_times, |
|
|
|
b.license, |
|
|
|
b.task, |
|
|
|
b.release_id, |
|
|
|
b.user_id, |
|
|
|
b.repo_id, |
|
|
|
b.created_unix, |
|
|
|
b.updated_unix,(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment a where a.dataset_id=b.id) |
|
|
|
FROM public.dataset b where b.repo_id=NEW.id; |
|
|
|
|
|
|
|
CREATE OR REPLACE FUNCTION public.update_repository() RETURNS trigger AS |
|
|
|
$def$ |
|
|
|
BEGIN |
|
|
|
if OLD.is_private != NEW.is_private then |
|
|
|
if OLD.is_private and not NEW.is_private then |
|
|
|
--delete |
|
|
|
INSERT INTO public.issue_es( |
|
|
|
id, |
|
|
|
repo_id, |
|
|
|
index, |
|
|
|
poster_id, |
|
|
|
original_author, |
|
|
|
original_author_id, |
|
|
|
name, |
|
|
|
content, |
|
|
|
milestone_id, |
|
|
|
priority, |
|
|
|
is_closed, |
|
|
|
is_pull, |
|
|
|
num_comments, |
|
|
|
ref, |
|
|
|
deadline_unix, |
|
|
|
created_unix, |
|
|
|
updated_unix, |
|
|
|
closed_unix, |
|
|
|
is_locked, |
|
|
|
amount, |
|
|
|
is_transformed,comment,pr_id) |
|
|
|
SELECT |
|
|
|
b.id, |
|
|
|
b.repo_id, |
|
|
|
b.index, |
|
|
|
b.poster_id, |
|
|
|
b.original_author, |
|
|
|
b.original_author_id, |
|
|
|
b.name, |
|
|
|
b.content, |
|
|
|
b.milestone_id, |
|
|
|
b.priority, |
|
|
|
b.is_closed, |
|
|
|
b.is_pull, |
|
|
|
b.num_comments, |
|
|
|
b.ref, |
|
|
|
b.deadline_unix, |
|
|
|
b.created_unix, |
|
|
|
b.updated_unix, |
|
|
|
b.closed_unix, |
|
|
|
b.is_locked, |
|
|
|
b.amount, |
|
|
|
b.is_transformed, |
|
|
|
(select array_to_string(array_agg(content order by created_unix desc),',') from public.comment a where a.issue_id=b.id), |
|
|
|
(select id from public.pull_request d where d.issue_id=b.id) |
|
|
|
FROM public.issue b where b.repo_id=NEW.id; |
|
|
|
|
|
|
|
INSERT INTO public.pull_request_es( |
|
|
|
id, |
|
|
|
type, |
|
|
|
status, |
|
|
|
conflicted_files, |
|
|
|
commits_ahead, |
|
|
|
commits_behind, |
|
|
|
issue_id, |
|
|
|
index, |
|
|
|
head_repo_id, |
|
|
|
base_repo_id, |
|
|
|
head_branch, |
|
|
|
base_branch, |
|
|
|
merge_base, |
|
|
|
has_merged, |
|
|
|
merged_commit_id, |
|
|
|
merger_id, |
|
|
|
merged_unix, |
|
|
|
is_transformed, |
|
|
|
amount) |
|
|
|
SELECT |
|
|
|
b.id, |
|
|
|
b.type, |
|
|
|
b.status, |
|
|
|
b.conflicted_files, |
|
|
|
b.commits_ahead, |
|
|
|
b.commits_behind, |
|
|
|
b.issue_id, |
|
|
|
b.index, |
|
|
|
b.head_repo_id, |
|
|
|
b.base_repo_id, |
|
|
|
b.head_branch, |
|
|
|
b.base_branch, |
|
|
|
b.merge_base, |
|
|
|
b.has_merged, |
|
|
|
b.merged_commit_id, |
|
|
|
b.merger_id, |
|
|
|
b.merged_unix, |
|
|
|
b.is_transformed, |
|
|
|
b.amount |
|
|
|
FROM public.pull_request b where b.base_repo_id=NEW.id; |
|
|
|
|
|
|
|
end if; |
|
|
|
|
|
|
|
if not OLD.is_private and NEW.is_private then |
|
|
|
delete from public.issue_es where repo_id=NEW.id; |
|
|
|
delete from public.dataset_es where repo_id=NEW.id; |
|
|
|
delete from public.pull_request_es where base_repo_id=NEW.id; |
|
|
|
delete from public.repository_es where id=NEW.id; |
|
|
|
end if; |
|
|
|
|
|
|
|
end if; |
|
|
|
|
|
|
|
update public.repository_es SET description=NEW.description, |
|
|
|
name=NEW.name, |
|
|
|
lower_name=NEW.lower_name, |
|
|
|
owner_name=NEW.owner_name, |
|
|
|
website=NEW.website, |
|
|
|
updated_unix=NEW.updated_unix, |
|
|
|
num_watches=NEW.num_watches, |
|
|
|
num_stars=NEW.num_stars, |
|
|
|
num_forks=NEW.num_forks, |
|
|
|
topics=NEW.topics |
|
|
|
where id=NEW.id; |
|
|
|
return new; |
|
|
|
if not NEW.is_private then |
|
|
|
update public.repository_es SET description=NEW.description, |
|
|
|
name=NEW.name, |
|
|
|
lower_name=NEW.lower_name, |
|
|
|
owner_name=NEW.owner_name, |
|
|
|
website=NEW.website, |
|
|
|
updated_unix=NEW.updated_unix, |
|
|
|
num_watches=NEW.num_watches, |
|
|
|
num_stars=NEW.num_stars, |
|
|
|
num_forks=NEW.num_forks, |
|
|
|
topics=NEW.topics |
|
|
|
where id=NEW.id; |
|
|
|
return new; |
|
|
|
end if; |
|
|
|
END |
|
|
|
$def$ |
|
|
|
LANGUAGE plpgsql; |
|
|
|
@@ -281,6 +492,9 @@ CREATE OR REPLACE FUNCTION public.delete_repository() RETURNS trigger AS |
|
|
|
$def$ |
|
|
|
declare |
|
|
|
BEGIN |
|
|
|
delete from public.issue_es where repo_id=OLD.id; |
|
|
|
delete from public.dataset_es where repo_id=OLD.id; |
|
|
|
delete from public.pull_request_es where base_repo_id=OLD.id; |
|
|
|
DELETE FROM public.repository_es where id=OLD.id; |
|
|
|
return new; |
|
|
|
END |
|
|
|
|