-
-
Notifications
You must be signed in to change notification settings - Fork 433
feat(dashboard): tenant migrations page #1866
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9f5df10
feat(dashboard): tenant migrations page
leandrocp a1bdfc8
fix Tenants.Connect -> Database.connect_db
leandrocp 9eb362c
apply action
leandrocp e300fdd
add pg_version in tenant info
leandrocp b48eb1d
ci
leandrocp 1ed7921
compressed pgdelta bin
leandrocp a8cd55a
fixes
leandrocp cac9a59
tests
leandrocp 932f292
Merge branch 'main' into lp-dashboard-pg-delta
leandrocp 61b09b6
allow blacksmith-2vcpu-ubuntu-2404
leandrocp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| self-hosted-runner: | ||
| labels: | ||
| - blacksmith-2vcpu-ubuntu-2404 | ||
| - blacksmith-4vcpu-ubuntu-2404 | ||
| - blacksmith-8vcpu-ubuntu-2404 | ||
| - arm-runner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| defmodule Mix.Tasks.Realtime.ExportTenantDbBaseline do | ||
| @shortdoc "Regenerate priv/repo/tenant_db_baseline.json" | ||
|
|
||
| @moduledoc """ | ||
| Writes the baseline catalog snapshot at `priv/repo/tenant_db_baseline.json` | ||
| used by `RealtimeWeb.Dashboard.TenantMigrations` to detect drifted DB state. | ||
|
|
||
| Usage: | ||
|
|
||
| mix realtime.export_tenant_db_baseline | ||
|
|
||
| The target DB is read from `DB_HOST` / `DB_PORT` / `DB_NAME` / `DB_USER` / | ||
| `DB_PASSWORD` env vars. | ||
|
|
||
| The target DB is expected to already have all tenant migrations applied. | ||
|
|
||
| Requires `pgdelta` on `$PATH`. | ||
| """ | ||
| use Mix.Task | ||
|
|
||
| @baseline_path "priv/repo/tenant_db_baseline.json" | ||
|
|
||
| @impl Mix.Task | ||
| def run(_args) do | ||
| url = build_url_from_env() | ||
| Mix.shell().info("[export_tenant_db_baseline] target: #{redact(url)}") | ||
|
|
||
| unless System.find_executable("pgdelta") do | ||
| Mix.raise("pgdelta not found on PATH") | ||
| end | ||
|
|
||
| output = Path.expand(@baseline_path, File.cwd!()) | ||
| args = ["catalog-export", "--target", url, "--output", output] | ||
|
|
||
| case System.cmd("pgdelta", args, stderr_to_stdout: true) do | ||
| {output_str, 0} -> | ||
| validate_snapshot!(output) | ||
| Mix.shell().info(output_str) | ||
|
|
||
| {output_str, code} -> | ||
| Mix.raise("pgdelta catalog-export exited #{code}:\n#{output_str}") | ||
| end | ||
| end | ||
|
|
||
| defp build_url_from_env do | ||
| host = System.get_env("DB_HOST", "127.0.0.1") | ||
| port = System.get_env("DB_PORT", "5433") | ||
| name = System.get_env("DB_NAME", "postgres") | ||
| user = System.get_env("DB_USER", "supabase_admin") | ||
| password = System.get_env("DB_PASSWORD", "postgres") | ||
|
|
||
| "postgresql://#{URI.encode_www_form(user)}:#{URI.encode_www_form(password)}@#{host}:#{port}/#{name}" | ||
| end | ||
|
|
||
| defp validate_snapshot!(path) do | ||
| with {:ok, content} <- File.read(path), | ||
| {:ok, _} <- Jason.decode(content) do | ||
| :ok | ||
| else | ||
| _ -> Mix.raise("baseline snapshot at #{path} is invalid") | ||
| end | ||
| end | ||
|
|
||
| defp redact(url) do | ||
| case URI.parse(url) do | ||
| %URI{userinfo: nil} = u -> | ||
| URI.to_string(u) | ||
|
|
||
| %URI{userinfo: userinfo} = u -> | ||
| user = userinfo |> String.split(":", parts: 2) |> hd() | ||
| URI.to_string(%{u | userinfo: "#{user}:***"}) | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.