feat: fixed migration for electric-sql

This commit is contained in:
Anish Sarkar 2026-01-14 23:23:45 +05:30
parent 5712336feb
commit 7a9a14aa66
4 changed files with 84 additions and 78 deletions

View file

@ -1,11 +0,0 @@
-- Electrify tables for Electric SQL sync
-- This tells Electric SQL which tables to sync
-- Run this after running migrations
-- Electrify notifications table
ALTER TABLE notifications ENABLE ELECTRIC;
-- You can electrify other tables as needed:
-- ALTER TABLE documents ENABLE ELECTRIC;
-- ALTER TABLE logs ENABLE ELECTRIC;

View file

@ -1,30 +0,0 @@
-- Create Electric SQL replication user
-- This script is run during PostgreSQL initialization
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_user WHERE usename = 'electric') THEN
CREATE USER electric WITH REPLICATION PASSWORD 'electric_password';
END IF;
END
$$;
-- Grant necessary permissions
GRANT CONNECT ON DATABASE surfsense TO electric;
GRANT USAGE ON SCHEMA public TO electric;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO electric;
GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO electric;
-- Grant permissions on future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO electric;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO electric;
-- Create the publication that Electric SQL expects
-- Electric will add tables to this publication when shapes are subscribed
DO $$
BEGIN
IF NOT EXISTS (SELECT FROM pg_publication WHERE pubname = 'electric_publication_default') THEN
CREATE PUBLICATION electric_publication_default;
END IF;
END
$$;