Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move electric_phoenix package into monorepo #2300

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions .github/workflows/electric_phoenix_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Electric Phoenix CI

on:
push:
branches: ["main"]
pull_request:

permissions:
contents: read

jobs:
build:
name: Build and test
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/electric-phoenix
env:
MIX_ENV: test
POSTGRES_VERSION: 140006
ELECTRIC_PORT: 3100
PG_PORT: 54324
ELECTRIC_URL: "http://127.0.0.1:3100"
DATABASE_URL: "postgresql://postgres:[email protected]:54324/postgres?sslmode=disable"
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_PASSWORD: password
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 54324:5432
steps:
- uses: actions/checkout@v4
- name: "Set PG settings"
run: |
docker exec ${{ job.services.postgres.id }} sh -c 'echo "wal_level=logical" >> /var/lib/postgresql/data/postgresql.conf'
docker restart ${{ job.services.postgres.id }}

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"

- name: Cache electric-phoenix dependencies
uses: actions/cache@v4
with:
path: packages/electric-phoenix/deps
key: ${{ runner.os }}-electric-phoenix-deps-${{ hashFiles('packages/electric-phoenix/mix.lock') }}
restore-keys: |
${{ runner.os }}-electric-phoenix-deps-${{ hashFiles('packages/electric-phoenix/mix.lock') }}
${{ runner.os }}-electric-phoenix-deps-

- name: Cache electric-phoenix compiled code
uses: actions/cache@v4
with:
path: |
packages/electric-phoenix/_build/*/lib
!packages/electric-phoenix/_build/*/lib/electric_client
key: "${{ runner.os }}-electric-phoenix-build-[${{ github.ref_name }}]-${{ github.sha }}"
restore-keys: |
${{ runner.os }}-electric-phoenix-build-[${{ github.ref_name }}]-${{ github.sha }}
${{ runner.os }}-electric-phoenix-build-[${{ github.ref_name }}]-
${{ runner.os }}-electric-phoenix-build-

- name: Install dependencies
run: mix deps.get && mix deps.compile

- name: Compiles without warnings
run: mix compile --force --all-warnings --warnings-as-errors

- name: Run tests
run: mix test

formatting:
name: Check formatting
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/electric-phoenix
env:
MIX_ENV: test
steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
with:
version-type: strict
version-file: ".tool-versions"

- name: Cache dependencies
id: cache-deps
uses: actions/cache/restore@v4
with:
path: packages/electric-phoenix/deps
key: ${{ runner.os }}-electric-phoenix-deps-${{ hashFiles('packages/electric-phoenix/mix.lock') }}
restore-keys: |
${{ runner.os }}-electric-phoenix-deps-${{ hashFiles('packages/electric-phoenix/mix.lock') }}
${{ runner.os }}-electric-phoenix-deps-

- run: mix deps.get

- run: mix format --check-formatted
34 changes: 28 additions & 6 deletions examples/phoenix-liveview/config/dev.exs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import Config

# Configure your database
config :electric_phoenix_example, Electric.PhoenixExample.Repo,
connection_opts = [
username: "postgres",
password: "password",
hostname: "localhost",
database: "electric",
port: 54321,
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
port: 54321
]

# Configure your database
config :electric_phoenix_example,
Electric.PhoenixExample.Repo,
Keyword.merge(connection_opts,
stacktrace: true,
show_sensitive_data_on_connection_error: true,
pool_size: 10
)

# For development, we disable any cache and enable
# debugging and code reloading.
Expand Down Expand Up @@ -86,3 +92,19 @@ config :phoenix_live_view,
config :electric_phoenix, Electric.Client,
base_url: System.get_env("ELECTRIC_URL", "http://localhost:3000/"),
params: System.get_env("ELECTRIC_CLIENT_PARAMS", "{}") |> :json.decode()

config :sentry,
environment_name: config_env(),
client: Electric.Telemetry.SentryReqHTTPClient

config :electric,
# connection_opts: Electric.Utils.obfuscate_password(connection_opts),
connection_opts: connection_opts,
# enable the http api so that the client tests against a real endpoint can
# run against our embedded electric instance.
enable_http_api: false,
allow_shape_deletion?: false,
# use a non-default replication stream id so we can run the client
# tests at the same time as an active electric instance
replication_stream_id: "liveview_example",
storage_dir: Path.join(System.tmp_dir!(), "electric/liveview_example#{System.monotonic_time()}")
19 changes: 19 additions & 0 deletions examples/phoenix-liveview/config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,23 @@ if config_env() == :prod do
base_url:
System.get_env("ELECTRIC_URL") || raise("ELECTRIC_URL environment variable not set"),
params: System.get_env("ELECTRIC_CLIENT_PARAMS", "{}") |> :json.decode()

config :sentry,
environment_name: config_env(),
client: Electric.Telemetry.SentryReqHTTPClient

connection_opts = Electric.Config.parse_postgresql_uri!(database_url)

config :electric,
connection_opts: Electric.Utils.obfuscate_password(connection_opts),
# enable the http api so that the client tests against a real endpoint can
# run against our embedded electric instance.
enable_http_api: false,
service_port: port,
allow_shape_deletion?: false,
# use a non-default replication stream id so we can run the client
# tests at the same time as an active electric instance
replication_stream_id: "liveview_example",
storage_dir:
Path.join(System.tmp_dir!(), "electric/liveview_example#{System.monotonic_time()}")
end
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ defmodule Electric.PhoenixExample.Application do

@impl true
def start(_type, _args) do
electric_config = Electric.Application.api_config()

children = [
Electric.PhoenixExampleWeb.Telemetry,
Electric.PhoenixExample.Repo,
Expand All @@ -16,7 +18,7 @@ defmodule Electric.PhoenixExample.Application do
# Start a worker by calling: Electric.PhoenixExample.Worker.start_link(arg)
# {Electric.PhoenixExample.Worker, arg},
# Start to serve requests, typically the last entry
Electric.PhoenixExampleWeb.Endpoint
{Electric.PhoenixExampleWeb.Endpoint, electric: electric_config}
]

# See https://hexdocs.pm/elixir/Supervisor.html
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ defmodule Electric.PhoenixExampleWeb.Router do
use Electric.PhoenixExampleWeb, :router

pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {Electric.PhoenixExampleWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
plug(:accepts, ["html"])
plug(:fetch_session)
plug(:fetch_live_flash)
plug(:put_root_layout, html: {Electric.PhoenixExampleWeb.Layouts, :root})
plug(:protect_from_forgery)
plug(:put_secure_browser_headers)
end

pipeline :api do
plug :accepts, ["json"]
plug(:accepts, ["json"])
end

scope "/", Electric.PhoenixExampleWeb do
pipe_through :browser
pipe_through(:browser)

live "/", TodoLive.Index, :index
live("/", TodoLive.Index, :index)
end

scope "/shapes" do
pipe_through(:api)

get("/", Electric.Phoenix.Plug.Shapes, [])
end

# Other scopes may use custom stacks.
Expand Down
4 changes: 3 additions & 1 deletion examples/phoenix-liveview/mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ defmodule Electric.PhoenixExample.MixProject do
{:jason, "~> 1.2"},
{:dns_cluster, "~> 0.1.1"},
{:bandit, "~> 1.5"},
{:electric_phoenix, "~> 0.2.0"},
# {:electric_phoenix, "~> 0.2.0"},
{:electric_phoenix, env: :dev, path: "../../packages/electric-phoenix/"},
# {:electric, path: "../../packages/sync-service"},
{:electric_client, ">= 0.2.6-pre-1", override: true}
]
end
Expand Down
Loading