Skip to content

Commit 9aea732

Browse files
fix: merge migrate_0.5.0.sql into migrate_0.4.9.9.sql
version_compare('0.5.0', '0.4.9.9', '<=') is FALSE in PHP, so migrate_0.5.0.sql would never execute when upgrading to 0.4.9.9. Merged its contents (sharing settings, plugin_hooks unique index) into migrate_0.4.9.9.sql. All statements are idempotent.
1 parent 3f5c438 commit 9aea732

File tree

3 files changed

+50
-67
lines changed

3 files changed

+50
-67
lines changed

installer/database/migrations/migrate_0.4.9.9.sql

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,52 @@ SET @sql = IF(@col_exists = 0,
2626
PREPARE stmt FROM @sql;
2727
EXECUTE stmt;
2828
DEALLOCATE PREPARE stmt;
29+
30+
-- =============================================================================
31+
-- Add default sharing providers setting
32+
-- =============================================================================
33+
-- Enables Facebook, X, WhatsApp and Email share buttons on the book detail page.
34+
-- Admins can customise the selection in Settings > Sharing.
35+
36+
INSERT IGNORE INTO system_settings (category, setting_key, setting_value, updated_at)
37+
VALUES ('sharing', 'enabled_providers', 'facebook,x,whatsapp,email', NOW());
38+
39+
-- =============================================================================
40+
-- Add unique index on plugin_hooks for atomic upsert registration
41+
-- =============================================================================
42+
-- Prevents duplicate hook rows from concurrent registerHooks() calls.
43+
-- First, deduplicate existing rows (keep the one with the smallest id).
44+
45+
DELETE ph1
46+
FROM plugin_hooks ph1
47+
JOIN plugin_hooks ph2
48+
ON ph1.plugin_id = ph2.plugin_id
49+
AND ph1.hook_name = ph2.hook_name
50+
AND ph1.callback_method = ph2.callback_method
51+
AND ph1.id > ph2.id;
52+
53+
-- Drop old 4-column unique key if it exists (included callback_class which
54+
-- is NOT part of the runtime identity — the dispatcher deduplicates by
55+
-- plugin_id + hook_name + callback_method only)
56+
SET @old_idx = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
57+
WHERE TABLE_SCHEMA = DATABASE()
58+
AND TABLE_NAME = 'plugin_hooks'
59+
AND INDEX_NAME = 'uk_plugin_hook_callback');
60+
SET @sql = IF(@old_idx > 0,
61+
'ALTER TABLE plugin_hooks DROP INDEX uk_plugin_hook_callback',
62+
'SELECT 1');
63+
PREPARE stmt FROM @sql;
64+
EXECUTE stmt;
65+
DEALLOCATE PREPARE stmt;
66+
67+
-- Re-create with correct 3-column key
68+
SET @new_idx = (SELECT COUNT(*) FROM INFORMATION_SCHEMA.STATISTICS
69+
WHERE TABLE_SCHEMA = DATABASE()
70+
AND TABLE_NAME = 'plugin_hooks'
71+
AND INDEX_NAME = 'uk_plugin_hook_callback');
72+
SET @sql = IF(@new_idx = 0,
73+
'ALTER TABLE plugin_hooks ADD UNIQUE KEY uk_plugin_hook_callback (plugin_id, hook_name, callback_method)',
74+
'SELECT 1');
75+
PREPARE stmt FROM @sql;
76+
EXECUTE stmt;
77+
DEALLOCATE PREPARE stmt;

installer/database/migrations/migrate_0.5.0.sql

Lines changed: 0 additions & 65 deletions
This file was deleted.

updater.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,7 @@ migrate_0.4.6.sql # LibraryThing missing fields (dewey_wording, barcode, entr
426426
migrate_0.4.7.sql # LibraryThing comprehensive migration (25+ fields, indexes, constraints)
427427
migrate_0.4.8.1.sql # Import logs tracking system (import_logs table + composite index)
428428
migrate_0.4.8.2.sql # Illustratore field, lingua expansion, language normalization, anno_pubblicazione signed
429-
migrate_0.4.9.9.sql # descrizione_plain column (HTML-free search)
430-
migrate_0.5.0.sql # Social sharing settings + descrizione_plain safety net
429+
migrate_0.4.9.9.sql # descrizione_plain column, social sharing settings, plugin_hooks unique index
431430
```
432431

433432
See `installer/database/migrations/README.md` for detailed migration documentation.

0 commit comments

Comments
 (0)