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:
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "oikos",
|
"name": "oikos",
|
||||||
"version": "0.43.0",
|
"version": "0.44.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "oikos",
|
"name": "oikos",
|
||||||
"version": "0.43.0",
|
"version": "0.44.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bcrypt": "^6.0.0",
|
"bcrypt": "^6.0.0",
|
||||||
|
|||||||
+3
-4
@@ -1006,8 +1006,6 @@ const MIGRATIONS = [
|
|||||||
// Update external_calendars source
|
// Update external_calendars source
|
||||||
db.prepare(`UPDATE external_calendars SET source='caldav' WHERE source='apple'`).run();
|
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
|
// Add caldav to external_source CHECK constraint by recreating table
|
||||||
@@ -1050,8 +1048,9 @@ const MIGRATIONS = [
|
|||||||
attachment_name, attachment_mime, attachment_size, attachment_data,
|
attachment_name, attachment_mime, attachment_size, attachment_data,
|
||||||
created_at, updated_at)
|
created_at, updated_at)
|
||||||
SELECT id, title, description, start_datetime, end_datetime, all_day, location, color,
|
SELECT id, title, description, start_datetime, end_datetime, all_day, location, color,
|
||||||
assigned_to, created_by, external_calendar_id, external_source, recurrence_rule,
|
assigned_to, created_by, external_calendar_id,
|
||||||
subscription_id, user_modified, calendar_ref_id, icon,
|
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,
|
attachment_name, attachment_mime, attachment_size, attachment_data,
|
||||||
created_at, updated_at
|
created_at, updated_at
|
||||||
FROM calendar_events
|
FROM calendar_events
|
||||||
|
|||||||
@@ -153,4 +153,40 @@ describe('CalDAV Multi-Account Sync', () => {
|
|||||||
assert.strictEqual(enabled.length, 1, 'Should have 1 enabled calendar');
|
assert.strictEqual(enabled.length, 1, 'Should have 1 enabled calendar');
|
||||||
assert.strictEqual(enabled[0].calendar_name, 'Private');
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user