|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- CREATE FOREIGN TABLE public."dataset_es"
- (
- id bigint NOT NULL,
- title character varying(255),
- status integer,
- category character varying(255),
- description text,
- download_times bigint,
- license character varying(255),
- task character varying(255),
- release_id bigint,
- user_id bigint,
- repo_id bigint,
- created_unix bigint,
- updated_unix bigint,
- file_name text
- )SERVER multicorn_es
- OPTIONS
- (
- host '192.168.207.94',
- port '9200',
- index 'user_es-index',
- rowid_column 'id'
- )
- ;
-
- CREATE OR REPLACE FUNCTION public.insert_dataset_data() RETURNS trigger AS
- $def$
- BEGIN
- INSERT INTO public.dataset_es(
- id,
- title,
- status,
- category,
- description,
- download_times,
- license, task,
- release_id,
- user_id,
- repo_id,
- created_unix,
- updated_unix)
- VALUES (
- NEW.id,
- NEW.title,
- NEW.status,
- NEW.category,
- NEW.description,
- NEW.download_times,
- NEW.license,
- NEW.task,
- NEW.release_id,
- NEW.user_id,
- NEW.repo_id,
- NEW.created_unix,
- NEW.updated_unix
- );
- RETURN NEW;
- END;
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_insert_dataset on public.dataset;
-
- CREATE TRIGGER es_insert_dataset
- AFTER INSERT ON public.dataset
- FOR EACH ROW EXECUTE PROCEDURE insert_dataset_data();
-
- CREATE OR REPLACE FUNCTION public.udpate_dataset_file_name() RETURNS trigger AS
- $def$
- BEGIN
- if (TG_OP = 'DELETE') then
- update public.dataset_es SET file_name=(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment where dataset_id=OLD.dataset_id order by created_unix desc) where id=OLD.dataset_id;
- elsif (TG_OP = 'INSERT') then
- update public.dataset_es SET file_name=(select array_to_string(array_agg(name order by created_unix desc),',') from public.attachment where dataset_id=NEW.dataset_id order by created_unix desc) where id=NEW.dataset_id;
- end if;
-
- return null;
- END;
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_udpate_dataset_file_name on public.attachment;
- CREATE TRIGGER es_udpate_dataset_file_name
- AFTER INSERT OR DELETE ON public.attachment
- FOR EACH ROW EXECUTE PROCEDURE udpate_dataset_file_name();
-
-
- CREATE OR REPLACE FUNCTION public.update_dataset_description() RETURNS trigger AS
- $def$
- declare
- BEGIN
- UPDATE public.dataset_es SET description=NEW.description where id=NEW.id;
- return new;
- END
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_update_dataset_description on public.dataset;
-
- CREATE TRIGGER es_update_dataset_description
- AFTER UPDATE OF "description" ON public.dataset
- FOR EACH ROW EXECUTE PROCEDURE update_dataset_description();
-
-
- CREATE OR REPLACE FUNCTION public.update_dataset_title() RETURNS trigger AS
- $def$
- declare
- BEGIN
- UPDATE public.dataset_es SET title=NEW.title where id=NEW.id;
- return new;
- END
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_update_dataset_title on public.dataset;
-
- CREATE TRIGGER es_update_dataset_title
- AFTER UPDATE OF "title" ON public.dataset
- FOR EACH ROW EXECUTE PROCEDURE update_dataset_title();
-
-
- CREATE OR REPLACE FUNCTION public.update_dataset_category() RETURNS trigger AS
- $def$
- declare
- BEGIN
- UPDATE public.dataset_es SET category=NEW.category where id=NEW.id;
- return new;
- END
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_update_dataset_category on public.dataset;
-
- CREATE TRIGGER es_update_dataset_category
- AFTER UPDATE OF "category" ON public.dataset
- FOR EACH ROW EXECUTE PROCEDURE update_dataset_category();
-
-
- CREATE OR REPLACE FUNCTION public.delete_dataset() RETURNS trigger AS
- $def$
- declare
- BEGIN
- DELETE FROM public.dataset_es where id=OLD.id;
- return new;
- END
- $def$
- LANGUAGE plpgsql;
-
- DROP TRIGGER IF EXISTS es_delete_dataset on public.dataset;
- CREATE TRIGGER es_delete_dataset
- AFTER DELETE ON public.dataset
- FOR EACH ROW EXECUTE PROCEDURE delete_dataset();
-
-
|