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

Drop all databases on DELETE /v1/admin/databases #1968

Closed
wants to merge 2 commits into from

Conversation

robacourt
Copy link
Contributor

Fixes #1923

Copy link
Contributor

@kevin-dp kevin-dp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, left some minor comments.

plug :delete_tenant

defp delete_tenant(conn, _) do
case TenantManager.delete_all_tenants(conn.assigns.config) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance this looked like it would fail to respond to the HTTP request if the deletion failed.
Looking further i realised that delete_all_tenants will/should always return :ok.
So the case statement seems unnecessary. This would be equivalent:

:ok = TenantManager.delete_all_tenants(conn.assigns.config)
conn
|> send_resp(200, Jason.encode_to_iodata!(%{}))
|> halt()

@@ -2,6 +2,7 @@ defmodule Electric.Plug.RemoveDatabasePlug do
use Plug.Builder

alias Plug.Conn

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change

plug :put_resp_content_type, "application/json"
plug :delete_tenant

defp delete_tenant(conn, _) do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named delete_tenants


assert conn.status == 200

assert Electric.Tenant.Persistence.load_tenants!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if loading from persistence is the right thing to check here.
I'd check that Electric.TenantManager.get_only_tenant(config) returns {:error, :not_found}

@robacourt
Copy link
Contributor Author

Closing as the purpose of this PR is to allow is to allow users of electric (not the cloud) to clear all replication slots so they can permanently stop electric. But since the multi-tenancy separation there is no concept of "all databases" now in electric, there is only one database, so all we need is an endpoint to delete the one database, which I'll do on a separate PR.

@robacourt robacourt closed this Nov 19, 2024
@robacourt robacourt deleted the rob/drop-all-databases branch November 19, 2024 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terminate electric admin endpoint
2 participants