From e7205c1334ba594ff1b53f1a51da620662e5ac32 Mon Sep 17 00:00:00 2001 From: Arsalan Khan Date: Fri, 27 Sep 2024 17:24:21 +0200 Subject: [PATCH] add custom metrics strategy FK in database --- .../api/db/servicebroker.db.changelog.yaml | 47 ++++++++++++++++++- src/autoscaler/db/sqldb/binding_sqldb_test.go | 15 ++++-- 2 files changed, 57 insertions(+), 5 deletions(-) diff --git a/src/autoscaler/api/db/servicebroker.db.changelog.yaml b/src/autoscaler/api/db/servicebroker.db.changelog.yaml index fa55a7318b..d6c6978c8e 100644 --- a/src/autoscaler/api/db/servicebroker.db.changelog.yaml +++ b/src/autoscaler/api/db/servicebroker.db.changelog.yaml @@ -78,9 +78,39 @@ databaseChangeLog: - column: name: custom_metrics_strategy type: varchar(40) - - changeSet: id: 3 + author: Arsalan + logicalFilePath: /var/vcap/packages/golangapiserver/servicebroker.db.changelog.json + preConditions: + - onFail: MARK_RAN + not: + - tableExists: + tableName: metrics_submission + changes: + - createTable: + tableName: metrics_submission + columns: + - column: + name: custom_metrics_strategy + type: varchar(40) + constraints: + primaryKey: true + - insert: + tableName: metrics_submission + columns: + - column: + name: custom_metrics_strategy + value: 'bound_app' + - insert: + tableName: metrics_submission + columns: + - column: + name: custom_metrics_strategy + value: 'same_app' + + - changeSet: + id: 4 author: qy logicalFilePath: /var/vcap/packages/golangapiserver/servicebroker.db.changelog.json preConditions: @@ -88,6 +118,8 @@ databaseChangeLog: not: - foreignKeyConstraintExists: foreignKeyName: fk_binding_service_instance_id + - foreignKeyConstraintExists: + foreignKeyName: fk_binding_custom_metrics_strategy changes: - addForeignKeyConstraint: baseColumnNames: service_instance_id @@ -99,8 +131,19 @@ databaseChangeLog: onUpdate: RESTRICT referencedColumnNames: service_instance_id referencedTableName: service_instance + + - addForeignKeyConstraint: + baseColumnNames: custom_metrics_strategy + baseTableName: binding + constraintName: fk_binding_custom_metrics_strategy + deferrable: false + initiallyDeferred: false + onDelete: RESTRICT + onUpdate: RESTRICT + referencedColumnNames: custom_metrics_strategy + referencedTableName: metrics_submission - changeSet: - id: 4 + id: 5 author: silvestre logicalFilePath: /var/vcap/packages/golangapiserver/servicebroker.db.changelog.yaml preConditions: diff --git a/src/autoscaler/db/sqldb/binding_sqldb_test.go b/src/autoscaler/db/sqldb/binding_sqldb_test.go index 0798525274..a052424c77 100644 --- a/src/autoscaler/db/sqldb/binding_sqldb_test.go +++ b/src/autoscaler/db/sqldb/binding_sqldb_test.go @@ -669,7 +669,7 @@ var _ = Describe("BindingSqldb", func() { err = bdb.CreateServiceInstance(context.Background(), models.ServiceInstance{ServiceInstanceId: testInstanceId, OrgId: testOrgGuid, SpaceId: testSpaceGuid, DefaultPolicy: policyJsonStr, DefaultPolicyGuid: policyGuid}) Expect(err).NotTo(HaveOccurred()) }) - Context("When configuration bounded_app is provided", func() { + When("configuration bounded_app is provided", func() { JustBeforeEach(func() { err = bdb.CreateServiceBindingWithConfigs(context.Background(), testBindingId, testInstanceId, testAppId, "bound_app") Expect(err).NotTo(HaveOccurred()) @@ -679,7 +679,7 @@ var _ = Describe("BindingSqldb", func() { }) }) - Context("When default configuration is provided", func() { + When("default configuration is provided", func() { JustBeforeEach(func() { err = bdb.CreateServiceBindingWithConfigs(context.Background(), testBindingId, testInstanceId, testAppId, "same_app") Expect(err).NotTo(HaveOccurred()) @@ -690,10 +690,19 @@ var _ = Describe("BindingSqldb", func() { }) }) + When("configuration is not provided", func() { + JustBeforeEach(func() { + err = bdb.CreateServiceBindingWithConfigs(context.Background(), testBindingId, testInstanceId, testAppId, "") + + }) + It("should throw an error with foreign key violation", func() { + Expect(err).To(HaveOccurred()) + }) + }) }) - FDescribe("GetCustomMetricStrategyByAppId", func() { + Describe("GetCustomMetricStrategyByAppId", func() { BeforeEach(func() { err = bdb.CreateServiceInstance(context.Background(), models.ServiceInstance{ServiceInstanceId: testInstanceId, OrgId: testOrgGuid, SpaceId: testSpaceGuid, DefaultPolicy: policyJsonStr, DefaultPolicyGuid: policyGuid}) Expect(err).NotTo(HaveOccurred())