Sync family members with contacts and birthdays

This commit is contained in:
Rafael Foster
2026-04-28 20:04:13 -03:00
parent 6f8cc712a7
commit 7b85db9b07
22 changed files with 426 additions and 45 deletions
+20
View File
@@ -748,6 +748,26 @@ const MIGRATIONS = [
UPDATE calendar_events SET icon = 'drill' WHERE icon = 'tooth';
`,
},
{
version: 23,
description: 'Link family members with contacts and birthdays',
up: `
ALTER TABLE contacts ADD COLUMN family_user_id INTEGER REFERENCES users(id) ON DELETE CASCADE;
CREATE UNIQUE INDEX IF NOT EXISTS idx_contacts_family_user
ON contacts(family_user_id) WHERE family_user_id IS NOT NULL;
ALTER TABLE birthdays ADD COLUMN family_user_id INTEGER REFERENCES users(id) ON DELETE CASCADE;
CREATE UNIQUE INDEX IF NOT EXISTS idx_birthdays_family_user
ON birthdays(family_user_id) WHERE family_user_id IS NOT NULL;
INSERT INTO contacts (name, category, family_user_id)
SELECT display_name, 'Sonstiges', id
FROM users
WHERE NOT EXISTS (
SELECT 1 FROM contacts WHERE contacts.family_user_id = users.id
);
`,
},
];
/**