Skip to content

Commit

Permalink
chore: drop unused Location and URL database fields (#1108)
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm authored Oct 4, 2024
1 parent eabd3d6 commit f8bb85e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
17 changes: 11 additions & 6 deletions dbservice/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/cloudfoundry/cloud-service-broker/v2/dbservice/models"
)

const numMigrations = 18
const numMigrations = 17

// RunMigrations runs schema migrations on the provided service broker database to get it up to date
func RunMigrations(db *gorm.DB) error {
Expand Down Expand Up @@ -129,11 +129,16 @@ func RunMigrations(db *gorm.DB) error {
}

migrations[16] = func() error {
return db.Migrator().DropColumn(&models.ServiceInstanceDetailsV3{}, "operation_type")
}

migrations[17] = func() error {
return db.Migrator().DropColumn(&models.ServiceInstanceDetailsV3{}, "operation_id")
if err := db.Migrator().DropColumn(&models.ServiceInstanceDetailsV4{}, "operation_type"); err != nil {
return err
}
if err := db.Migrator().DropColumn(&models.ServiceInstanceDetailsV4{}, "operation_id"); err != nil {
return err
}
if err := db.Migrator().DropColumn(&models.ServiceInstanceDetailsV4{}, "location"); err != nil {
return err
}
return db.Migrator().DropColumn(&models.ServiceInstanceDetailsV4{}, "url")
}

var lastMigrationNumber = -1
Expand Down
2 changes: 0 additions & 2 deletions dbservice/models/historical_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,6 @@ type ServiceInstanceDetailsV4 struct {
DeletedAt *time.Time

Name string
Location string
URL string
OtherDetails []byte `gorm:"type:blob"`

ServiceID string
Expand Down
6 changes: 0 additions & 6 deletions internal/storage/service_instance_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
type ServiceInstanceDetails struct {
GUID string
Name string
Location string
URL string
Outputs JSONObject
ServiceGUID string
PlanGUID string
Expand All @@ -31,8 +29,6 @@ func (s *Storage) StoreServiceInstanceDetails(d ServiceInstanceDetails) error {
}

m.Name = d.Name
m.Location = d.Location
m.URL = d.URL
m.OtherDetails = encoded
m.ServiceID = d.ServiceGUID
m.PlanID = d.PlanGUID
Expand Down Expand Up @@ -84,8 +80,6 @@ func (s *Storage) GetServiceInstanceDetails(guid string) (ServiceInstanceDetails
return ServiceInstanceDetails{
GUID: guid,
Name: receiver.Name,
Location: receiver.Location,
URL: receiver.URL,
Outputs: decoded,
ServiceGUID: receiver.ServiceID,
PlanGUID: receiver.PlanID,
Expand Down
16 changes: 0 additions & 16 deletions internal/storage/service_instance_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ var _ = Describe("ServiceInstanceDetails", func() {
err := store.StoreServiceInstanceDetails(storage.ServiceInstanceDetails{
GUID: "fake-guid",
Name: "fake-name",
Location: "fake-location",
URL: "fake-url",
Outputs: map[string]any{"foo": "bar"},
ServiceGUID: "fake-service-guid",
PlanGUID: "fake-plan-guid",
Expand All @@ -29,8 +27,6 @@ var _ = Describe("ServiceInstanceDetails", func() {
Expect(db.Find(&receiver).Error).NotTo(HaveOccurred())
Expect(receiver.ID).To(Equal("fake-guid"))
Expect(receiver.Name).To(Equal("fake-name"))
Expect(receiver.Location).To(Equal("fake-location"))
Expect(receiver.URL).To(Equal("fake-url"))
Expect(receiver.OtherDetails).To(Equal([]byte(`{"encrypted":{"foo":"bar"}}`)))
Expect(receiver.ServiceID).To(Equal("fake-service-guid"))
Expect(receiver.PlanID).To(Equal("fake-plan-guid"))
Expand All @@ -56,8 +52,6 @@ var _ = Describe("ServiceInstanceDetails", func() {
err := store.StoreServiceInstanceDetails(storage.ServiceInstanceDetails{
GUID: "fake-id-1",
Name: "fake-name",
Location: "fake-location",
URL: "fake-url",
Outputs: map[string]any{"foo": "bar"},
ServiceGUID: "fake-service-guid",
PlanGUID: "fake-plan-guid",
Expand All @@ -70,8 +64,6 @@ var _ = Describe("ServiceInstanceDetails", func() {
Expect(db.Where(`id = "fake-id-1"`).Find(&receiver).Error).NotTo(HaveOccurred())
Expect(receiver.ID).To(Equal("fake-id-1"))
Expect(receiver.Name).To(Equal("fake-name"))
Expect(receiver.Location).To(Equal("fake-location"))
Expect(receiver.URL).To(Equal("fake-url"))
Expect(receiver.OtherDetails).To(Equal([]byte(`{"encrypted":{"foo":"bar"}}`)))
Expect(receiver.ServiceID).To(Equal("fake-service-guid"))
Expect(receiver.PlanID).To(Equal("fake-plan-guid"))
Expand All @@ -91,8 +83,6 @@ var _ = Describe("ServiceInstanceDetails", func() {
Expect(err).NotTo(HaveOccurred())

Expect(r.GUID).To(Equal("fake-id-2"))
Expect(r.Location).To(Equal("fake-location-2"))
Expect(r.URL).To(Equal("fake-url-2"))
Expect(r.Outputs).To(Equal(storage.JSONObject{"decrypted": map[string]any{"foo": "bar-2"}}))
Expect(r.ServiceGUID).To(Equal("fake-service-id-2"))
Expect(r.PlanGUID).To(Equal("fake-plan-id-2"))
Expand Down Expand Up @@ -194,8 +184,6 @@ func addFakeServiceInstanceDetails() {
Expect(db.Create(&models.ServiceInstanceDetails{
ID: "fake-id-1",
Name: "fake-name-1",
Location: "fake-location-1",
URL: "fake-url-1",
OtherDetails: []byte(`{"foo":"bar-1"}`),
ServiceID: "fake-service-id-1",
PlanID: "fake-plan-id-1",
Expand All @@ -205,8 +193,6 @@ func addFakeServiceInstanceDetails() {
Expect(db.Create(&models.ServiceInstanceDetails{
ID: "fake-id-2",
Name: "fake-name-2",
Location: "fake-location-2",
URL: "fake-url-2",
OtherDetails: []byte(`{"foo":"bar-2"}`),
ServiceID: "fake-service-id-2",
PlanID: "fake-plan-id-2",
Expand All @@ -216,8 +202,6 @@ func addFakeServiceInstanceDetails() {
Expect(db.Create(&models.ServiceInstanceDetails{
ID: "fake-id-3",
Name: "fake-name-3",
Location: "fake-location-3",
URL: "fake-url-3",
OtherDetails: []byte(`{"foo":"bar-3"}`),
ServiceID: "fake-service-id-3",
PlanID: "fake-plan-id-3",
Expand Down

0 comments on commit f8bb85e

Please sign in to comment.