33 if($dbManager == NULL){
34 echo
"No connection object passed!\n";
40 DROP SEQUENCE IF EXISTS public.author_pk_seq CASCADE; 42 ALTER TABLE ONLY public.author 43 DROP CONSTRAINT IF EXISTS author_agent_fk_fkey CASCADE; 44 ALTER TABLE ONLY public.author 45 DROP CONSTRAINT IF EXISTS author_pfile_fk_fkey CASCADE; 46 ALTER TABLE ONLY public.author 47 DROP CONSTRAINT IF EXISTS author_pkey CASCADE; 49 $dbManager->queryOnce($sql);
51 CREATE SEQUENCE public.author_pk_seq; 52 SELECT setval('public.author_pk_seq',(SELECT greatest(1,max($authorColumn)) val FROM author)); 53 ALTER TABLE public.author ALTER COLUMN $authorColumn SET DEFAULT nextval('author_pk_seq'::regclass); 55 DROP INDEX IF EXISTS author_agent_fk_idx; 56 DROP INDEX IF EXISTS author_pfile_fk_index; 57 DROP INDEX IF EXISTS author_pfile_hash_idx; 58 DROP INDEX IF EXISTS author_pkey; 60 ALTER SEQUENCE public.author_pk_seq RESTART WITH 1; 61 UPDATE public.author SET $authorColumn=nextval('public.author_pk_seq'); 63 ALTER TABLE ONLY public.author 64 ADD CONSTRAINT author_pkey PRIMARY KEY ($authorColumn); 66 CREATE INDEX author_agent_fk_idx ON public.author USING btree (agent_fk); 67 CREATE INDEX author_pfile_fk_index ON public.author USING btree (pfile_fk); 68 CREATE INDEX author_pfile_hash_idx ON public.author USING btree (hash, pfile_fk); 69 ALTER TABLE ONLY public.author 70 ADD CONSTRAINT author_agent_fk_fkey FOREIGN KEY (agent_fk) REFERENCES public.agent(agent_pk) ON DELETE CASCADE; 71 ALTER TABLE ONLY public.author 72 ADD CONSTRAINT author_pfile_fk_fkey FOREIGN KEY (pfile_fk) REFERENCES public.pfile(pfile_pk) ON DELETE CASCADE; 76 $dbManager->queryOnce($sql);
87 if($dbManager == NULL){
88 echo
"No connection object passed!\n";
94 ALTER TABLE ONLY public.copyright 95 DROP CONSTRAINT IF EXISTS copyright_pkey CASCADE; 96 ALTER TABLE ONLY public.copyright 97 DROP CONSTRAINT IF EXISTS copyright_agent_fk_fkey CASCADE; 98 DROP INDEX IF EXISTS copyright_pkey; 99 DROP SEQUENCE IF EXISTS public.copyright_pk_seq CASCADE; 101 $dbManager->queryOnce($sql);
103 CREATE SEQUENCE public.copyright_pk_seq; 104 SELECT setval('public.copyright_pk_seq',(SELECT greatest(1,max($copyrightColumn)) val FROM copyright)); 105 ALTER TABLE public.copyright ALTER COLUMN $copyrightColumn SET DEFAULT nextval('copyright_pk_seq'::regclass); 106 ALTER SEQUENCE public.copyright_pk_seq RESTART WITH 1; 107 UPDATE public.copyright SET $copyrightColumn=nextval('public.copyright_pk_seq'); 109 ALTER TABLE ONLY public.copyright 110 ADD CONSTRAINT copyright_pkey PRIMARY KEY ($copyrightColumn); 111 ALTER TABLE ONLY public.copyright 112 ADD CONSTRAINT copyright_agent_fk_fkey FOREIGN KEY (agent_fk) REFERENCES public.agent(agent_pk) ON DELETE CASCADE; 116 $dbManager->queryOnce($sql);
128 if($dbManager == NULL){
129 echo
"No connection object passed!\n";
135 DELETE FROM public.author 136 USING public.author AS a LEFT OUTER JOIN public.pfile AS p ON p.pfile_pk = a.pfile_fk 137 WHERE public.author.$authorColumn = a.$authorColumn AND p.pfile_pk IS NULL; 139 DELETE FROM public.author 140 USING public.author AS au LEFT OUTER JOIN public.agent AS ag ON au.agent_fk = ag.agent_pk 141 WHERE public.author.$authorColumn = au.$authorColumn AND ag.agent_pk IS NULL; 143 DELETE FROM public.author 144 WHERE $authorColumn IN (SELECT $authorColumn 145 FROM (SELECT $authorColumn, 146 ROW_NUMBER() OVER (PARTITION BY hash, pfile_fk, agent_fk, copy_startbyte, copy_endbyte, type 147 ORDER BY $authorColumn) AS rnum 148 FROM public.author) a 152 $dbManager->queryOnce($sql);
163 if($dbManager == NULL){
164 echo
"No connection object passed!\n";
171 DELETE FROM public.copyright 172 USING public.copyright AS cp LEFT OUTER JOIN public.agent AS ag ON cp.agent_fk = ag.agent_pk 173 WHERE public.copyright.$copyrightColumn = cp.$copyrightColumn AND ag.agent_pk IS NULL; 177 $dbManager->queryOnce($sql);
180 $result = $dbManager->getSingleRow(
"SELECT count(*) FROM pg_class WHERE relname = 'author_pk_seq';",
181 array(),
'checkAuthorCtPkSequence');
182 if($result[
'count'] == 0)
184 $DatabaseName = $GLOBALS[
"SysConf"][
"DBCONF"][
"dbname"];
185 $authorColumn =
DB_ColExists(
"author",
"ct_pk", $DatabaseName) == 1 ?
"ct_pk" :
"author_pk";
186 $copyrightColumn =
DB_ColExists(
"copyright",
"ct_pk", $DatabaseName) == 1 ?
"ct_pk" :
"copyright_pk";
189 echo
"*** Cleaning author table ***\n";
191 echo
"*** Cleaning copyright table ***\n";
193 echo
"*** Resequencing author table ***\n";
195 echo
"*** Resequencing copyright table ***\n";
197 }
catch (Exception $e) {
198 echo
"Something went wrong. Try running postinstall again!\n";
199 $dbManager->queryOnce(
"ROLLBACK;");
ResequenceCopyrightTablePKey($dbManager, $copyrightColumn)
Drop primary key constrains and resequence the copyright table and build them again.
ResequenceAuthorTablePKey($dbManager, $authorColumn)
Drop all sequence and constrains and resequence the author table and build them again.
CleanAuthorTable($dbManager, $authorColumn)
Remove redundant entries from author table.
CleanCopyrightTable($dbManager, $copyrightColumn)
Remove invalid entries from copyright table.
DB_ColExists($tableName, $colName, $DBName='fossology')
Check if a column exists.