Skip to content

Commit

Permalink
Drop unique app name index
Browse files Browse the repository at this point in the history
It is possible two apps share the same name, however the package is the
only thing that will stay unique. So we can safely drop the unique name
db constraint, and let apps get added that are the same name. They will
look different in most cases due to image/package.

This resolves: techlore/Plexus-app#33
  • Loading branch information
tomkonidas committed Jul 15, 2024
1 parent e28c7c3 commit 9236f86
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
1 change: 0 additions & 1 deletion lib/plexus/schemas/app.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule Plexus.Schemas.App do
app
|> cast(params, [:package, :name, :icon_url])
|> validate_required([:package, :name])
|> unique_constraint(:name)
|> unique_constraint(:package, name: :apps_pkey)
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Plexus.Repo.Migrations.RemoveAppsNameUniqueIndex do
use Ecto.Migration

def change do
drop_if_exists index(:apps, [:name])
end
end
7 changes: 0 additions & 7 deletions test/plexus/apps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,5 @@ defmodule Plexus.AppsTest do
attrs = %{package: app.package, name: unique_app_name()}
assert {:error, %Ecto.Changeset{}} = Apps.create_app(attrs)
end

test "with duplicate name returns error changeset" do
app = app_fixture()

attrs = %{package: unique_app_package(), name: app.name}
assert {:error, %Ecto.Changeset{}} = Apps.create_app(attrs)
end
end
end
8 changes: 0 additions & 8 deletions test/plexus_web/controllers/api/v1/app_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ defmodule PlexusWeb.API.V1.AppControllerTest do
} = json_response(conn, 422)
end

test "renders error when name is already taken", %{conn: conn} do
app = app_fixture()
attrs = %{@create_attrs | name: app.name}

conn = post(conn, ~p"/api/v1/apps", app: attrs)
assert %{"errors" => %{"name" => ["has already been taken"]}} = json_response(conn, 422)
end

test "renders error when package is already taken", %{conn: conn} do
app = app_fixture()
attrs = %{@create_attrs | package: app.package}
Expand Down

0 comments on commit 9236f86

Please sign in to comment.