Skip to content

Commit

Permalink
add custom metrics strategy FK in database
Browse files Browse the repository at this point in the history
  • Loading branch information
asalan316 committed Oct 1, 2024
1 parent 9084d13 commit e7205c1
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
47 changes: 45 additions & 2 deletions src/autoscaler/api/db/servicebroker.db.changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,48 @@ 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:
- onFail: MARK_RAN
not:
- foreignKeyConstraintExists:
foreignKeyName: fk_binding_service_instance_id
- foreignKeyConstraintExists:
foreignKeyName: fk_binding_custom_metrics_strategy
changes:
- addForeignKeyConstraint:
baseColumnNames: service_instance_id
Expand All @@ -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:
Expand Down
15 changes: 12 additions & 3 deletions src/autoscaler/db/sqldb/binding_sqldb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand Down

0 comments on commit e7205c1

Please sign in to comment.