22 if($dbManager == NULL){
23 echo
"No connection object passed!\n";
29 DROP SEQUENCE IF EXISTS public.author_pk_seq CASCADE;
31 ALTER TABLE ONLY public.author
32 DROP CONSTRAINT IF EXISTS author_agent_fk_fkey CASCADE;
33 ALTER TABLE ONLY public.author
34 DROP CONSTRAINT IF EXISTS author_pfile_fk_fkey CASCADE;
35 ALTER TABLE ONLY public.author
36 DROP CONSTRAINT IF EXISTS author_pkey CASCADE;
38 $dbManager->queryOnce($sql);
40 CREATE SEQUENCE public.author_pk_seq;
41 SELECT setval('public.author_pk_seq',(SELECT greatest(1,max($authorColumn)) val FROM author));
42 ALTER TABLE public.author ALTER COLUMN $authorColumn SET DEFAULT nextval('author_pk_seq'::regclass);
44 DROP INDEX IF EXISTS author_agent_fk_idx;
45 DROP INDEX IF EXISTS author_pfile_fk_index;
46 DROP INDEX IF EXISTS author_pfile_hash_idx;
47 DROP INDEX IF EXISTS author_pkey;
49 ALTER SEQUENCE public.author_pk_seq RESTART WITH 1;
50 UPDATE public.author SET $authorColumn=nextval('public.author_pk_seq');
52 ALTER TABLE ONLY public.author
53 ADD CONSTRAINT author_pkey PRIMARY KEY ($authorColumn);
55 CREATE INDEX author_agent_fk_idx ON public.author USING btree (agent_fk);
56 CREATE INDEX author_pfile_fk_index ON public.author USING btree (pfile_fk);
57 CREATE INDEX author_pfile_hash_idx ON public.author USING btree (hash, pfile_fk);
58 ALTER TABLE ONLY public.author
59 ADD CONSTRAINT author_agent_fk_fkey FOREIGN KEY (agent_fk) REFERENCES public.agent(agent_pk) ON DELETE CASCADE;
60 ALTER TABLE ONLY public.author
61 ADD CONSTRAINT author_pfile_fk_fkey FOREIGN KEY (pfile_fk) REFERENCES public.pfile(pfile_pk) ON DELETE CASCADE;
65 $dbManager->queryOnce($sql);
76 if($dbManager == NULL){
77 echo
"No connection object passed!\n";
83 ALTER TABLE ONLY public.copyright
84 DROP CONSTRAINT IF EXISTS copyright_pkey CASCADE;
85 ALTER TABLE ONLY public.copyright
86 DROP CONSTRAINT IF EXISTS copyright_agent_fk_fkey CASCADE;
87 DROP INDEX IF EXISTS copyright_pkey;
88 DROP SEQUENCE IF EXISTS public.copyright_pk_seq CASCADE;
90 $dbManager->queryOnce($sql);
92 CREATE SEQUENCE public.copyright_pk_seq;
93 SELECT setval('public.copyright_pk_seq',(SELECT greatest(1,max($copyrightColumn)) val FROM copyright));
94 ALTER TABLE public.copyright ALTER COLUMN $copyrightColumn SET DEFAULT nextval('copyright_pk_seq'::regclass);
95 ALTER SEQUENCE public.copyright_pk_seq RESTART WITH 1;
96 UPDATE public.copyright SET $copyrightColumn=nextval('public.copyright_pk_seq');
98 ALTER TABLE ONLY public.copyright
99 ADD CONSTRAINT copyright_pkey PRIMARY KEY ($copyrightColumn);
100 ALTER TABLE ONLY public.copyright
101 ADD CONSTRAINT copyright_agent_fk_fkey FOREIGN KEY (agent_fk) REFERENCES public.agent(agent_pk) ON DELETE CASCADE;
105 $dbManager->queryOnce($sql);
117 if($dbManager == NULL){
118 echo
"No connection object passed!\n";
124 DELETE FROM public.author
125 USING public.author AS a LEFT OUTER JOIN public.pfile AS p ON p.pfile_pk = a.pfile_fk
126 WHERE public.author.$authorColumn = a.$authorColumn AND p.pfile_pk IS NULL;
128 DELETE FROM public.author
129 USING public.author AS au LEFT OUTER JOIN public.agent AS ag ON au.agent_fk = ag.agent_pk
130 WHERE public.author.$authorColumn = au.$authorColumn AND ag.agent_pk IS NULL;
132 DELETE FROM public.author
133 WHERE $authorColumn IN (SELECT $authorColumn
134 FROM (SELECT $authorColumn,
135 ROW_NUMBER() OVER (PARTITION BY hash, pfile_fk, agent_fk, copy_startbyte, copy_endbyte, type
136 ORDER BY $authorColumn) AS rnum
137 FROM public.author) a
141 $dbManager->queryOnce($sql);
152 if($dbManager == NULL){
153 echo
"No connection object passed!\n";
160 DELETE FROM public.copyright
161 USING public.copyright AS cp LEFT OUTER JOIN public.agent AS ag ON cp.agent_fk = ag.agent_pk
162 WHERE public.copyright.$copyrightColumn = cp.$copyrightColumn AND ag.agent_pk IS NULL;
166 $dbManager->queryOnce($sql);
169 $result = $dbManager->getSingleRow(
"SELECT count(*) FROM pg_class WHERE relname = 'author_pk_seq';",
170 array(),
'checkAuthorCtPkSequence');
171 if($result[
'count'] == 0)
173 $DatabaseName = $GLOBALS[
"SysConf"][
"DBCONF"][
"dbname"];
174 $authorColumn =
DB_ColExists(
"author",
"ct_pk", $DatabaseName) == 1 ?
"ct_pk" :
"author_pk";
175 $copyrightColumn =
DB_ColExists(
"copyright",
"ct_pk", $DatabaseName) == 1 ?
"ct_pk" :
"copyright_pk";
178 echo
"*** Cleaning author table ***\n";
180 echo
"*** Cleaning copyright table ***\n";
182 echo
"*** Resequencing author table ***\n";
184 echo
"*** Resequencing copyright table ***\n";
186 }
catch (Exception $e) {
187 echo
"Something went wrong. Try running postinstall again!\n";
188 $dbManager->queryOnce(
"ROLLBACK;");
DB_ColExists($tableName, $colName, $DBName='fossology')
Check if a column exists.
ResequenceCopyrightTablePKey($dbManager, $copyrightColumn)
Drop primary key constrains and resequence the copyright table and build them again.
CleanCopyrightTable($dbManager, $copyrightColumn)
Remove invalid entries from copyright table.
CleanAuthorTable($dbManager, $authorColumn)
Remove redundant entries from author table.
ResequenceAuthorTablePKey($dbManager, $authorColumn)
Drop all sequence and constrains and resequence the author table and build them again.