summaryrefslogtreecommitdiffstats
path: root/application/migrations/014_deduplicate_file_storage.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/migrations/014_deduplicate_file_storage.php')
-rw-r--r--application/migrations/014_deduplicate_file_storage.php20
1 files changed, 8 insertions, 12 deletions
diff --git a/application/migrations/014_deduplicate_file_storage.php b/application/migrations/014_deduplicate_file_storage.php
index 96c041c27..bd96c56d8 100644
--- a/application/migrations/014_deduplicate_file_storage.php
+++ b/application/migrations/014_deduplicate_file_storage.php
@@ -81,18 +81,14 @@ class Migration_deduplicate_file_storage extends CI_Migration {
// XXX: This query also exists in migration 15
$this->db->query('
- DELETE `'.$prefix.'file_storage`
- FROM `'.$prefix.'file_storage`
- LEFT OUTER JOIN `'.$prefix.'files` ON `'.$prefix.'files`.file_storage_id = `'.$prefix.'file_storage`.id
- WHERE `'.$prefix.'file_storage`.id NOT IN (
- SELECT min(x.id)
- FROM (
- SELECT fs.id, fs.hash
- FROM `'.$prefix.'file_storage` fs
- ) x
- GROUP BY x.hash
- )
- AND `'.$prefix.'files`.id IS NULL
+ DELETE fs
+ FROM `'.$prefix.'file_storage` fs, `'.$prefix.'file_storage` fs2
+ WHERE fs.hash = fs2.hash
+ AND fs.id > fs2.id
+ AND fs.id NOT IN (
+ SELECT file_storage_id
+ FROM `'.$prefix.'files` f
+ );
');
}