Skip to content
9 changes: 8 additions & 1 deletion scripts/docker/entrypoint-allinone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ if [ ! -f /data/postgres/PG_VERSION ]; then
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON SEQUENCES TO ${ELECTRIC_DB_USER};

-- Create the publication for Electric SQL (if not exists)
-- Must use FOR ALL TABLES so Electric can sync all tables
DO \\\$\\\$
BEGIN
IF NOT EXISTS (SELECT FROM pg_publication WHERE pubname = 'electric_publication_default') THEN
CREATE PUBLICATION electric_publication_default;
CREATE PUBLICATION electric_publication_default FOR ALL TABLES;
END IF;
END
\\\$\\\$;
Expand Down Expand Up @@ -180,6 +181,12 @@ run_migrations() {
cd /app/backend
alembic upgrade head || echo "⚠️ Migrations may have already been applied"

# Recreate Electric publication AFTER migrations so all tables are included
# FOR ALL TABLES only captures tables that exist at creation time
echo "📡 Refreshing Electric SQL publication..."
su - postgres -c "psql -d ${POSTGRES_DB:-financegpt} -c \"DROP PUBLICATION IF EXISTS electric_publication_default; CREATE PUBLICATION electric_publication_default FOR ALL TABLES;\""
echo "✅ Electric SQL publication refreshed with all tables"

# Stop temporary services
redis-cli shutdown || true
su - postgres -c "/usr/lib/postgresql/14/bin/pg_ctl -D /data/postgres stop"
Expand Down
Loading