diff --git a/lib/livebook/hubs/team.ex b/lib/livebook/hubs/team.ex index f6bab7b1d..f425fa61e 100644 --- a/lib/livebook/hubs/team.ex +++ b/lib/livebook/hubs/team.ex @@ -262,15 +262,11 @@ defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do def deployment_groups(team), do: TeamClient.get_deployment_groups(team.id) def get_app_specs(team) do - app_deployments = TeamClient.get_agent_app_deployments(team.id) - - for app_deployment <- app_deployments do - {seconds, _} = NaiveDateTime.to_gregorian_seconds(app_deployment.deployed_at) - + for app_deployment <- TeamClient.get_agent_app_deployments(team.id) do %Livebook.Apps.TeamsAppSpec{ slug: app_deployment.slug, - version: "#{app_deployment.id}-#{seconds}-#{app_deployment.sha}", - hub_id: team.id, + version: app_deployment.version, + hub_id: app_deployment.hub_id, app_deployment_id: app_deployment.id } end diff --git a/lib/livebook/hubs/team_client.ex b/lib/livebook/hubs/team_client.ex index 8ebf472c5..7328fb49c 100644 --- a/lib/livebook/hubs/team_client.ex +++ b/lib/livebook/hubs/team_client.ex @@ -454,6 +454,7 @@ defmodule Livebook.Hubs.TeamClient do %Teams.AppDeployment{ id: app_deployment.id, slug: app_deployment.slug, + version: app_deployment.version, sha: app_deployment.sha, title: app_deployment.title, multi_session: app_deployment.multi_session, diff --git a/lib/livebook/teams/app_deployment.ex b/lib/livebook/teams/app_deployment.ex index 47ec1c8cc..e48459c03 100644 --- a/lib/livebook/teams/app_deployment.ex +++ b/lib/livebook/teams/app_deployment.ex @@ -7,6 +7,7 @@ defmodule Livebook.Teams.AppDeployment do @type t :: %__MODULE__{ id: String.t() | nil, slug: String.t() | nil, + version: String.t() | nil, sha: String.t() | nil, title: String.t() | nil, multi_session: boolean(), @@ -23,6 +24,7 @@ defmodule Livebook.Teams.AppDeployment do @primary_key {:id, :string, autogenerate: false} embedded_schema do field :slug, :string + field :version, :string field :sha, :string field :title, :string field :multi_session, :boolean diff --git a/test/livebook_teams/hubs/team_client_test.exs b/test/livebook_teams/hubs/team_client_test.exs index c15e1d9c1..3b4ac8695 100644 --- a/test/livebook_teams/hubs/team_client_test.exs +++ b/test/livebook_teams/hubs/team_client_test.exs @@ -255,6 +255,7 @@ defmodule Livebook.Hubs.TeamClientTest do %LivebookProto.AppDeployment{ id: app_deployment.id, title: app_deployment.title, + version: app_deployment.version, slug: app_deployment.slug, sha: app_deployment.sha, deployed_by: app_deployment.deployed_by, @@ -656,9 +657,11 @@ defmodule Livebook.Hubs.TeamClientTest do # Since the app deployment struct generation is from Livebook side, # we don't have yet the information about who deployed the app, # so we need to add it ourselves. + app_deployment = %{ app_deployment | id: to_string(teams_app_deployment.id), + version: Livebook.Utils.random_id(), file: nil, deployed_by: teams_app_deployment.app_revision.created_by.name, deployed_at: teams_app_deployment.updated_at @@ -670,6 +673,7 @@ defmodule Livebook.Hubs.TeamClientTest do %LivebookProto.AppDeployment{ id: app_deployment.id, title: app_deployment.title, + version: app_deployment.version, slug: app_deployment.slug, sha: app_deployment.sha, deployed_by: app_deployment.deployed_by, diff --git a/test/support/factory.ex b/test/support/factory.ex index 7b87b2fa2..b1766dfd4 100644 --- a/test/support/factory.ex +++ b/test/support/factory.ex @@ -104,12 +104,18 @@ defmodule Livebook.Factory do content = :crypto.strong_rand_bytes(1024 * 1024) md5_hash = :crypto.hash(:md5, content) shasum = Base.encode16(md5_hash, case: :lower) - deployed_at = NaiveDateTime.utc_now() + + deployed_at = + NaiveDateTime.utc_now() + |> NaiveDateTime.truncate(:second) + + {seconds, 0} = NaiveDateTime.to_gregorian_seconds(deployed_at) %Livebook.Teams.AppDeployment{ id: "1", title: unique_value("MyNotebook-"), sha: shasum, + version: "1-#{shasum}-#{seconds}", slug: slug, file: content, multi_session: false, @@ -117,7 +123,7 @@ defmodule Livebook.Factory do hub_id: Livebook.Hubs.Personal.id(), deployment_group_id: "1", deployed_by: "Ada Lovelace", - deployed_at: NaiveDateTime.truncate(deployed_at, :second) + deployed_at: deployed_at } end