Skip to content

Commit 0a93ef4

Browse files
authored
Fix for ITEP-82840 - Added restriction as profile_name and image_id combination to be unique while creating OS Resource (#829)
1 parent d733532 commit 0a93ef4

File tree

8 files changed

+56
-33
lines changed

8 files changed

+56
-33
lines changed

inventory/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.34.3-dev
1+
2.34.3

inventory/api/os/v1/os.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ message OperatingSystemResource {
4646
"tenant_id"
4747
]
4848
},
49+
{
50+
unique: true
51+
fields: [
52+
"profile_name",
53+
"image_id",
54+
"tenant_id"
55+
]
56+
},
4957
{
5058
unique: false
5159
fields: ["tenant_id"]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Create the unique index
2+
-- Below comment suppresses Atlas data dependency warnings for this migration. This allows the index creation to proceed without checking for existing data conflicts
3+
-- The orchestrator upgrade might fail if there are existing duplicate records that violate the new unique constraint, so it's important to ensure that the data duplication is clean before applying this migration.
4+
-- atlas:nolint data_depend
5+
CREATE UNIQUE INDEX "operatingsystemresource_profile_name_image_id_tenant_id" ON "operating_system_resources" ("profile_name", "image_id", "tenant_id");

inventory/internal/ent/migrate/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:oA4Sukey1SgQuO9KEH3D9QCjrTHoy78kTKbUIj+WEz4=
1+
h1:DLi0FNlNPpZ9vMGntvI6zylJ2LZPP1LtGRzzhoIEOqY=
22
20230600000000_empty.sql h1:WTkYlwWwrdJjax+pXqrJYBNu1BIdqqnF9WoasjlGLUk=
33
20250324165719_all.sql h1:YEGDRbDPwxh5fBkoaGAwXpPu3nDCsCDdrvTt2EzBekk=
44
20250520125803_add_osprof_desc.sql h1:RQBqrgNfdTJlElMRdsizeMIRLsfw2Dq1LzzdiIV/JmE=
@@ -21,3 +21,4 @@ h1:oA4Sukey1SgQuO9KEH3D9QCjrTHoy78kTKbUIj+WEz4=
2121
20251103070349_add_tls_ca_cert.sql h1:UYrGjsK3nJwVkBoA/fxczxGFzYsh/wKqxAMXbPcWHRI=
2222
20251127155123_modify_OSUpdateRun_applied_policy_field.sql h1:HIrAbHZFtLI2j2pyiOVBbMj6BjQtnvYxAaAkl6PbRdw=
2323
20260127052128_modify_acm-ccm.sql h1:hl3kEP5gTAE8CBGSEMEs/3JKPL4PgM0JbejCLJTBnCM=
24+
20260202082730_modify_os_profile_name_image_id_unique_key.sql h1:iD5/FsBn19r+PNxGGzwAd93cBI+CIbcYCIyD/raMXWA=

inventory/internal/ent/migrate/schema.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inventory/internal/ent/schema/operating_system_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ func (OperatingSystemResource) Annotations() []schema.Annotation {
2323
return nil
2424
}
2525
func (OperatingSystemResource) Indexes() []ent.Index {
26-
return []ent.Index{index.Fields("name", "tenant_id").Unique(), index.Fields("tenant_id")}
26+
return []ent.Index{index.Fields("name", "tenant_id").Unique(), index.Fields("profile_name", "image_id", "tenant_id").Unique(), index.Fields("tenant_id")}
2727
}

inventory/pkg/api/os/v1/os.pb.go

Lines changed: 33 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inventory/sql/inventory.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ CREATE INDEX "siteresource_tenant_id" ON "site_resources" ("tenant_id");
1818
CREATE TABLE "operating_system_resources" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "resource_id" character varying NOT NULL, "name" character varying NULL, "architecture" character varying NULL, "image_url" character varying NULL, "image_id" character varying NULL, "sha256" character varying NULL, "profile_name" character varying NULL, "profile_version" character varying NULL, "installed_packages" character varying NULL, "installed_packages_url" character varying NULL, "security_feature" character varying NULL, "os_type" character varying NULL, "os_provider" character varying NOT NULL, "platform_bundle" character varying NULL, "description" character varying NULL, "metadata" character varying NULL, "tls_ca_cert" character varying NULL, "existing_cves_url" character varying NULL, "existing_cves" character varying NULL, "fixed_cves_url" character varying NULL, "fixed_cves" character varying NULL, "tenant_id" character varying NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, PRIMARY KEY ("id"));
1919
CREATE UNIQUE INDEX "operating_system_resources_resource_id_key" ON "operating_system_resources" ("resource_id");
2020
CREATE UNIQUE INDEX "operatingsystemresource_name_tenant_id" ON "operating_system_resources" ("name", "tenant_id");
21+
CREATE UNIQUE INDEX "operatingsystemresource_profile_name_image_id_tenant_id" ON "operating_system_resources" ("profile_name", "image_id", "tenant_id");
2122
CREATE INDEX "operatingsystemresource_tenant_id" ON "operating_system_resources" ("tenant_id");
2223
CREATE TABLE "local_account_resources" ("id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, "resource_id" character varying NOT NULL, "username" character varying NOT NULL, "ssh_key" character varying NOT NULL, "tenant_id" character varying NOT NULL, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL, PRIMARY KEY ("id"));
2324
CREATE UNIQUE INDEX "local_account_resources_resource_id_key" ON "local_account_resources" ("resource_id");

0 commit comments

Comments
 (0)