-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1454 from eikek/migration-fix
Fix previously published db migration
- Loading branch information
Showing
7 changed files
with
189 additions
and
33 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
modules/store/src/main/resources/db/fixups/postgresql/V1.33.0__fix_reorganize_files.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
drop table if exists valid_file_ids; | ||
create table valid_file_ids ( | ||
id bigserial primary key, | ||
file_id varchar(254) not null unique | ||
); | ||
|
||
-- Source files | ||
insert into valid_file_ids (file_id) | ||
select rs.file_id | ||
from attachment_source rs | ||
; | ||
|
||
-- Archive files | ||
insert into valid_file_ids (file_id) | ||
select distinct rs.file_id | ||
from attachment_archive rs | ||
; | ||
|
||
-- Preview image | ||
insert into valid_file_ids (file_id) | ||
select ap.file_id | ||
from attachment_preview ap | ||
; | ||
|
||
-- classifier | ||
insert into valid_file_ids (file_id) | ||
select file_id | ||
from classifier_model | ||
; | ||
|
||
-- save obsolete files | ||
drop table if exists obsolete_files; | ||
create table obsolete_files( | ||
file_id varchar(254) not null | ||
); | ||
|
||
with | ||
missing_ids as ( | ||
select file_id from filemeta | ||
except | ||
select file_id as file_id from valid_file_ids) | ||
insert into obsolete_files (file_id) | ||
select file_id from filemeta | ||
where file_id in (select file_id from missing_ids) | ||
; | ||
|
||
|
||
-- remove orphaned chunks | ||
delete from "filechunk" | ||
where "file_id" in ( | ||
select distinct file_id from filechunk | ||
where file_id not in (select file_id from valid_file_ids) | ||
and file_id not in (select file_id from obsolete_files) | ||
); | ||
|
||
-- drop temp table | ||
drop table valid_file_ids; | ||
drop table obsolete_files; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters