mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-25 00:36:31 +02:00
feat: Add notifications table and integrate Electric SQL for real-time updates
- Introduced a new notifications table in the database schema to manage user notifications. - Implemented Electric SQL replication setup for the notifications table, ensuring real-time synchronization. - Updated existing database functions to support real-time updates for connectors and documents using Electric SQL. - Refactored UI components to utilize new hooks for fetching connectors and documents, enhancing performance and user experience.
This commit is contained in:
parent
7a92ecc1ab
commit
e38e6d90e0
9 changed files with 489 additions and 178 deletions
|
|
@ -939,13 +939,15 @@ async def create_db_and_tables():
|
|||
|
||||
|
||||
async def setup_electric_replication():
|
||||
"""Set up Electric SQL replication for the notifications table."""
|
||||
"""Set up Electric SQL replication for real-time sync tables."""
|
||||
async with engine.begin() as conn:
|
||||
# Set REPLICA IDENTITY FULL (required by Electric SQL for replication)
|
||||
# This logs full row data for UPDATE/DELETE operations in the WAL
|
||||
await conn.execute(text("ALTER TABLE notifications REPLICA IDENTITY FULL;"))
|
||||
await conn.execute(text("ALTER TABLE search_source_connectors REPLICA IDENTITY FULL;"))
|
||||
await conn.execute(text("ALTER TABLE documents REPLICA IDENTITY FULL;"))
|
||||
|
||||
# Add notifications table to Electric SQL publication for replication
|
||||
# Add tables to Electric SQL publication for replication
|
||||
# Only add if publication exists and table not already in it
|
||||
await conn.execute(
|
||||
text(
|
||||
|
|
@ -953,6 +955,7 @@ async def setup_electric_replication():
|
|||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (SELECT 1 FROM pg_publication WHERE pubname = 'electric_publication_default') THEN
|
||||
-- Add notifications if not already added
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_publication_tables
|
||||
WHERE pubname = 'electric_publication_default'
|
||||
|
|
@ -960,6 +963,24 @@ async def setup_electric_replication():
|
|||
) THEN
|
||||
ALTER PUBLICATION electric_publication_default ADD TABLE notifications;
|
||||
END IF;
|
||||
|
||||
-- Add search_source_connectors if not already added
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_publication_tables
|
||||
WHERE pubname = 'electric_publication_default'
|
||||
AND tablename = 'search_source_connectors'
|
||||
) THEN
|
||||
ALTER PUBLICATION electric_publication_default ADD TABLE search_source_connectors;
|
||||
END IF;
|
||||
|
||||
-- Add documents if not already added
|
||||
IF NOT EXISTS (
|
||||
SELECT 1 FROM pg_publication_tables
|
||||
WHERE pubname = 'electric_publication_default'
|
||||
AND tablename = 'documents'
|
||||
) THEN
|
||||
ALTER PUBLICATION electric_publication_default ADD TABLE documents;
|
||||
END IF;
|
||||
END IF;
|
||||
END
|
||||
$$;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue