From 8b26d125bb30c34224d99ee505397a0f9e0e6e8c Mon Sep 17 00:00:00 2001 From: michaeljguarino Date: Tue, 27 Aug 2024 21:50:37 -0400 Subject: [PATCH] Add legacy boolean to clusters (#1350) --- apps/core/lib/core/schema/cluster.ex | 3 ++- apps/core/lib/core/schema/upgrade_queue.ex | 3 ++- apps/core/lib/core/services/clusters.ex | 1 + .../20240827164453_add_legacy_flag_clusters.exs | 13 +++++++++++++ apps/core/test/services/clusters_test.exs | 8 +++++++- apps/graphql/lib/graphql/schema/cluster.ex | 2 ++ apps/graphql/lib/graphql/schema/upgrade.ex | 3 ++- schema/schema.graphql | 7 +++++++ www/src/generated/graphql.ts | 5 +++++ 9 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 apps/core/priv/repo/migrations/20240827164453_add_legacy_flag_clusters.exs diff --git a/apps/core/lib/core/schema/cluster.ex b/apps/core/lib/core/schema/cluster.ex index cfabbe03e..f3afe11f4 100644 --- a/apps/core/lib/core/schema/cluster.ex +++ b/apps/core/lib/core/schema/cluster.ex @@ -20,6 +20,7 @@ defmodule Core.Schema.Cluster do field :domain, :string field :pinged_at, :utc_datetime_usec field :service_count, :integer + field :legacy, :boolean belongs_to :owner, User belongs_to :account, Account @@ -85,7 +86,7 @@ defmodule Core.Schema.Cluster do from(c in query, order_by: ^order) end - @valid ~w(owner_id account_id provider name domain console_url source git_url pinged_at service_count)a + @valid ~w(owner_id legacy account_id provider name domain console_url source git_url pinged_at service_count)a def changeset(model, attrs \\ %{}) do model diff --git a/apps/core/lib/core/schema/upgrade_queue.ex b/apps/core/lib/core/schema/upgrade_queue.ex index be9b10a68..c4d7c7033 100644 --- a/apps/core/lib/core/schema/upgrade_queue.ex +++ b/apps/core/lib/core/schema/upgrade_queue.ex @@ -9,6 +9,7 @@ defmodule Core.Schema.UpgradeQueue do field :name, :string field :domain, :string field :git, :string + field :legacy, :boolean field :provider, Core.Schema.Recipe.Provider field :pinged_at, :utc_datetime_usec @@ -35,7 +36,7 @@ defmodule Core.Schema.UpgradeQueue do from(q in query, where: is_nil(q.cluster_id)) end - @valid ~w(acked user_id name domain git provider cluster_id)a + @valid ~w(acked legacy user_id name domain git provider cluster_id)a def changeset(model, attrs \\ %{}) do model diff --git a/apps/core/lib/core/services/clusters.ex b/apps/core/lib/core/services/clusters.ex index 5aaae9c29..00d65c6c4 100644 --- a/apps/core/lib/core/services/clusters.ex +++ b/apps/core/lib/core/services/clusters.ex @@ -158,6 +158,7 @@ defmodule Core.Services.Clusters do upsert_cluster(%{ console_url: d, domain: infer_domain(d), + legacy: q.legacy, git_url: g, pinged_at: pinged, }, p, n, user) diff --git a/apps/core/priv/repo/migrations/20240827164453_add_legacy_flag_clusters.exs b/apps/core/priv/repo/migrations/20240827164453_add_legacy_flag_clusters.exs new file mode 100644 index 000000000..b968949f4 --- /dev/null +++ b/apps/core/priv/repo/migrations/20240827164453_add_legacy_flag_clusters.exs @@ -0,0 +1,13 @@ +defmodule Core.Repo.Migrations.AddLegacyFlagClusters do + use Ecto.Migration + + def change do + alter table(:clusters) do + add :legacy, :boolean, default: true + end + + alter table(:upgrade_queues) do + add :legacy, :boolean, default: true + end + end +end diff --git a/apps/core/test/services/clusters_test.exs b/apps/core/test/services/clusters_test.exs index 05637c2f7..afe96ddb2 100644 --- a/apps/core/test/services/clusters_test.exs +++ b/apps/core/test/services/clusters_test.exs @@ -31,11 +31,17 @@ defmodule Core.Services.ClustersTest do describe "#create_from_queue/1" do test "it can create a new cluster from an upgrade queue" do - queue = insert(:upgrade_queue, domain: "console.plural.sh", git: "git@github.com/pluralsh/repo", provider: :aws) + queue = insert(:upgrade_queue, + domain: "console.plural.sh", + git: "git@github.com/pluralsh/repo", + provider: :aws, + legacy: true + ) {:ok, cluster} = Clusters.create_from_queue(queue) assert cluster.name == queue.name + assert cluster.legacy assert cluster.provider == queue.provider assert cluster.owner_id == queue.user_id assert cluster.account_id == queue.user.account_id diff --git a/apps/graphql/lib/graphql/schema/cluster.ex b/apps/graphql/lib/graphql/schema/cluster.ex index 48123478c..4bbd327ea 100644 --- a/apps/graphql/lib/graphql/schema/cluster.ex +++ b/apps/graphql/lib/graphql/schema/cluster.ex @@ -10,6 +10,7 @@ defmodule GraphQl.Schema.Cluster do input_object :cluster_attributes do field :name, non_null(:string), description: "The name of the cluster." field :provider, non_null(:provider), description: "The cluster's cloud provider." + field :legacy, :boolean, description: "whether this is a legacy oss cluster" field :source, :source, description: "The source of the cluster." field :git_url, :string, description: "The git repository URL for the cluster." field :console_url, :string, description: "The URL of the console running on the cluster." @@ -21,6 +22,7 @@ defmodule GraphQl.Schema.Cluster do field :id, non_null(:id), description: "The ID of the cluster." field :name, non_null(:string), description: "The name of the cluster." field :provider, non_null(:provider), description: "The cluster's cloud provider." + field :legacy, :boolean, description: "whether this is a legacy OSS cluster" field :source, :source, description: "The source of the cluster." field :git_url, :string, description: "The git repository URL for the cluster." field :console_url, :string, description: "The URL of the console running on the cluster." diff --git a/apps/graphql/lib/graphql/schema/upgrade.ex b/apps/graphql/lib/graphql/schema/upgrade.ex index 07bb976d1..9f3b27bfa 100644 --- a/apps/graphql/lib/graphql/schema/upgrade.ex +++ b/apps/graphql/lib/graphql/schema/upgrade.ex @@ -34,6 +34,7 @@ defmodule GraphQl.Schema.Upgrade do input_object :upgrade_queue_attributes do field :name, non_null(:string) + field :legacy, :boolean field :domain, :string field :git, :string field :provider, :provider @@ -129,8 +130,8 @@ defmodule GraphQl.Schema.Upgrade do object :upgrade_mutations do field :create_queue, :upgrade_queue do middleware Authenticated - arg :attributes, non_null(:upgrade_queue_attributes) + resolve &Upgrade.create_upgrade_queue/2 end diff --git a/schema/schema.graphql b/schema/schema.graphql index 3950e7b21..05f59be8e 100644 --- a/schema/schema.graphql +++ b/schema/schema.graphql @@ -1626,6 +1626,9 @@ type Cluster { "The cluster's cloud provider." provider: Provider! + "whether this is a legacy OSS cluster" + legacy: Boolean + "The source of the cluster." source: Source @@ -2837,6 +2840,9 @@ input ClusterAttributes { "The cluster's cloud provider." provider: Provider! + "whether this is a legacy oss cluster" + legacy: Boolean + "The source of the cluster." source: Source @@ -3675,6 +3681,7 @@ input StackAttributes { input UpgradeQueueAttributes { name: String! + legacy: Boolean domain: String git: String provider: Provider diff --git a/www/src/generated/graphql.ts b/www/src/generated/graphql.ts index ac13b3482..f19ec0e29 100644 --- a/www/src/generated/graphql.ts +++ b/www/src/generated/graphql.ts @@ -425,6 +425,8 @@ export type Cluster = { /** The ID of the cluster. */ id: Scalars['ID']['output']; insertedAt?: Maybe; + /** whether this is a legacy OSS cluster */ + legacy?: Maybe; /** whether any installation in the cluster has been locked */ locked?: Maybe; /** The name of the cluster. */ @@ -464,6 +466,8 @@ export type ClusterAttributes = { domain?: InputMaybe; /** The git repository URL for the cluster. */ gitUrl?: InputMaybe; + /** whether this is a legacy oss cluster */ + legacy?: InputMaybe; /** The name of the cluster. */ name: Scalars['String']['input']; /** The cluster's cloud provider. */ @@ -4926,6 +4930,7 @@ export type UpgradeQueueUpgradesArgs = { export type UpgradeQueueAttributes = { domain?: InputMaybe; git?: InputMaybe; + legacy?: InputMaybe; name: Scalars['String']['input']; provider?: InputMaybe; };