fix: remap apple external_source during CalDAV migration

Fixes #119

Moves apple→caldav conversion into table rebuild to avoid CHECK constraint violation during migration to v0.44.0.
This commit is contained in:
Copilot
2026-05-04 16:38:07 +02:00
committed by GitHub
parent 6cc72676c6
commit 21c85fd418
3 changed files with 41 additions and 6 deletions
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "oikos",
"version": "0.43.0",
"version": "0.44.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "oikos",
"version": "0.43.0",
"version": "0.44.0",
"license": "MIT",
"dependencies": {
"bcrypt": "^6.0.0",
+3 -4
View File
@@ -1006,8 +1006,6 @@ const MIGRATIONS = [
// Update external_calendars source
db.prepare(`UPDATE external_calendars SET source='caldav' WHERE source='apple'`).run();
// Update calendar_events external_source
db.prepare(`UPDATE calendar_events SET external_source='caldav' WHERE external_source='apple'`).run();
}
// Add caldav to external_source CHECK constraint by recreating table
@@ -1050,8 +1048,9 @@ const MIGRATIONS = [
attachment_name, attachment_mime, attachment_size, attachment_data,
created_at, updated_at)
SELECT id, title, description, start_datetime, end_datetime, all_day, location, color,
assigned_to, created_by, external_calendar_id, external_source, recurrence_rule,
subscription_id, user_modified, calendar_ref_id, icon,
assigned_to, created_by, external_calendar_id,
CASE WHEN external_source = 'apple' THEN 'caldav' ELSE external_source END,
recurrence_rule, subscription_id, user_modified, calendar_ref_id, icon,
attachment_name, attachment_mime, attachment_size, attachment_data,
created_at, updated_at
FROM calendar_events
+36
View File
@@ -153,4 +153,40 @@ describe('CalDAV Multi-Account Sync', () => {
assert.strictEqual(enabled.length, 1, 'Should have 1 enabled calendar');
assert.strictEqual(enabled[0].calendar_name, 'Private');
});
it('should migrate apple calendar events to caldav without violating CHECK', () => {
const db2 = new DatabaseSync(':memory:');
db2.exec(`
CREATE TABLE calendar_events (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
external_source TEXT NOT NULL DEFAULT 'local'
CHECK(external_source IN ('local', 'google', 'apple', 'ics'))
);
`);
db2.prepare(`
INSERT INTO calendar_events (title, external_source)
VALUES ('Migrated', 'apple')
`).run();
db2.exec(`
CREATE TABLE calendar_events_new (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
external_source TEXT NOT NULL DEFAULT 'local'
CHECK(external_source IN ('local', 'google', 'apple', 'ics', 'caldav'))
);
`);
db2.exec(`
INSERT INTO calendar_events_new (id, title, external_source)
SELECT id, title,
CASE WHEN external_source = 'apple' THEN 'caldav' ELSE external_source END
FROM calendar_events
`);
const migrated = db2.prepare(`SELECT external_source FROM calendar_events_new WHERE title = 'Migrated'`).get();
assert.strictEqual(migrated.external_source, 'caldav');
});
});