File: /volume1/@appstore/SynologyPhotos/etc/sql/150.sql
DO $$
BEGIN
IF NOT EXISTS (
SELECT 1 FROM pg_indexes
WHERE indexname = 'face_migration_id_user_id_unit_id_idx'
) THEN
RETURN;
END IF;
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_name = 'production_table_index_mapping'
) THEN
BEGIN
EXECUTE 'ALTER TABLE production_table_index_mapping DROP CONSTRAINT IF EXISTS production_table_index_mapping_tb_name_index_name_key';
EXECUTE 'ALTER TABLE production_table_index_mapping ADD CONSTRAINT production_table_index_mapping_tb_name_index_name_key UNIQUE (tb_name, index_name)';
END;
INSERT INTO production_table_index_mapping (tb_name, index_name, index_def)
VALUES ('face', 'face_unit_face_list_idx', 'btree (id_user, id_unit, id) WHERE (is_manual = false)')
ON CONFLICT (tb_name, index_name) DO NOTHING;
END IF;
END $$;