Skip to content

Instantly share code, notes, and snippets.

@jnturton
Last active November 19, 2024 03:14
Show Gist options
  • Save jnturton/a3ec351ca263000e0d8a7e6ed36e71bb to your computer and use it in GitHub Desktop.
Save jnturton/a3ec351ca263000e0d8a7e6ed36e71bb to your computer and use it in GitHub Desktop.
Migrate a local Thunderbird calendar from one profile to another
-- Uses sqlite operations to copy all local data related to source_cal_id in source_db_path
-- over to target_cal_id in the sqlite database that you connect to when you run this script.
-- The target calendar should be created in advance in Thunderbird and its ID discovered in
-- <profile_dir>/prefs.js e.g.
-- user_pref("calendar.registry.d6efb1bb-8553-4968-b597-372203a9a7f8.name", "Calendar Archive");
-- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- Runtime variables below are in DBeaver format.
attach database '${source_db_path}' as source;
insert
into
cal_alarms
select
'${target_cal_id}',
item_id,
recurrence_id,
recurrence_id_tz,
icalString
from
source.cal_alarms
where
source.cal_alarms.cal_id = '${source_cal_id}';
insert
into
cal_attachments
select
item_id,
'${target_cal_id}',
recurrence_id,
recurrence_id_tz,
icalString
from
source.cal_attachments
where
source.cal_attachments.cal_id = '${source_cal_id}';
insert into cal_attendees
select
item_id,
recurrence_id,
recurrence_id_tz,
'${target_cal_id}',
icalString
from
source.cal_attendees
where
source.cal_attendees.cal_id = '${source_cal_id}';
insert into cal_events
select
'${target_cal_id}',
id,
time_created,
last_modified,
title,
priority,
privacy,
ical_status,
flags,
event_start,
event_end,
event_stamp,
event_start_tz,
event_end_tz,
recurrence_id,
recurrence_id_tz,
alarm_last_ack,
offline_journal
from
source.cal_events
where source.cal_events.cal_id = '${source_cal_id}';
insert into cal_metadata
select
'${target_cal_id}',
item_id,
value
from
source.cal_metadata
where source.cal_metadata.cal_id = '${source_cal_id}';
insert into cal_parameters
select
'${target_cal_id}',
item_id,
recurrence_id,
recurrence_id_tz,
key1,
key2,
value
from
source.cal_parameters
where source.cal_parameters.cal_id = '${source_cal_id}';
insert into cal_properties
select
item_id,
"key",
value,
recurrence_id,
recurrence_id_tz,
'${target_cal_id}'
from
source.cal_properties
where source.cal_properties.cal_id = '${source_cal_id}';
insert into cal_recurrence
select
item_id,
'${target_cal_id}',
icalString
from
source.cal_recurrence
where source.cal_recurrence.cal_id = '${source_cal_id}';
insert into cal_relations
select
'${target_cal_id}',
item_id,
recurrence_id,
recurrence_id_tz,
icalString
from
source.cal_relations
where source.cal_relations.cal_id = '${source_cal_id}';
insert
into
cal_todos
select
'${target_cal_id}',
id,
time_created,
last_modified,
title,
priority,
privacy,
ical_status,
flags,
todo_entry,
todo_due,
todo_completed,
todo_complete,
todo_entry_tz,
todo_due_tz,
todo_completed_tz,
recurrence_id,
recurrence_id_tz,
alarm_last_ack,
todo_stamp,
offline_journal
from
source.cal_todos
where
source.cal_todos.cal_id = '${source_cal_id}';
detach database source;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment