warden-worker/migrations/0008_add_eq_domains.sql
qaz741wsd856 f179e4a015 feat: implement equivalent domains functionality
- Added support for equivalent domains in user settings, allowing users to define custom domain groups and exclude specific global groups.
- Introduced new migration script to add necessary database columns and a table for global equivalent domains.
- Created a Python script to generate seed SQL for global domains, which can be executed to populate the database.
- Updated API endpoints to handle equivalent domains, including retrieval and persistence of user-defined settings.
- Refactored existing settings handler to remove stubs and implement full functionality for managing equivalent domains.
2025-12-29 09:11:39 +00:00

31 lines
1.3 KiB
SQL

-- Migration: Add equivalent domains (eq_domains) functionality
--
-- Part 1: User settings fields for URI matching
-- - equivalent_domains: JSON string of Vec<Vec<String>> (custom groups)
-- - excluded_globals: JSON string of Vec<i32> (excluded global group IDs)
--
-- We keep defaults as "[]", and allow applying this migration multiple times
-- (duplicate column errors are handled gracefully by CI tooling).
--
-- Part 2: Global equivalent domains table
-- Stores the upstream "global domains" dataset (vaultwarden/Bitwarden compatible),
-- but kept OUT of the Worker bundle for size/perf reasons.
--
-- Data is seeded separately (see scripts) and may be refreshed over time.
-- Columns:
-- - type: the global group id (matches vaultwarden's `GlobalDomain.type`)
-- - sort_order: preserve upstream file order for stable client UX
-- - domains_json: JSON string of Vec<String> (domain list)
ALTER TABLE users ADD COLUMN equivalent_domains TEXT NOT NULL DEFAULT '[]';
ALTER TABLE users ADD COLUMN excluded_globals TEXT NOT NULL DEFAULT '[]';
CREATE TABLE IF NOT EXISTS global_equivalent_domains (
type INTEGER PRIMARY KEY NOT NULL,
sort_order INTEGER NOT NULL,
domains_json TEXT NOT NULL
);
CREATE INDEX IF NOT EXISTS idx_global_equivalent_domains_sort_order
ON global_equivalent_domains(sort_order);