-
Notifications
You must be signed in to change notification settings - Fork 6
/
fix_hilo_sequences.sql
33 lines (31 loc) · 1.3 KB
/
fix_hilo_sequences.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Fixes all HiLo sequences in case they are out of order
-- dehydrated_objects
BEGIN;
LOCK TABLE dehydrated_objects IN EXCLUSIVE MODE;
SELECT setval('dehydrated_objects_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('dehydrated_objects_hilo')) - 1 FROM dehydrated_objects));
COMMIT;
-- lfs_objects
BEGIN;
LOCK TABLE lfs_objects IN EXCLUSIVE MODE;
SELECT setval('lfs_objects_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('lfs_objects_hilo')) - 1 FROM lfs_objects));
COMMIT;
-- project_git_files
BEGIN;
LOCK TABLE project_git_files IN EXCLUSIVE MODE;
SELECT setval('project_git_files_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('project_git_files_hilo')) - 1 FROM project_git_files));
COMMIT;
-- storage_files
BEGIN;
LOCK TABLE storage_files IN EXCLUSIVE MODE;
SELECT setval('storage_files_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('storage_files_hilo')) - 1 FROM storage_files));
COMMIT;
-- storage_item_versions
BEGIN;
LOCK TABLE storage_item_versions IN EXCLUSIVE MODE;
SELECT setval('storage_item_versions_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('storage_item_versions_hilo')) - 1 FROM storage_item_versions));
COMMIT;
-- storage_items
BEGIN;
LOCK TABLE storage_items IN EXCLUSIVE MODE;
SELECT setval('storage_items_hilo', (SELECT GREATEST(MAX(id) + 1, nextval('storage_items_hilo')) - 1 FROM storage_items));
COMMIT;