Skip to content

Commit

Permalink
chore: drop unused Location and URL database fields
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm committed Oct 3, 2024
1 parent 69a15f4 commit 4286395
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
6 changes: 5 additions & 1 deletion 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 = 16
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 @@ -128,6 +128,10 @@ func RunMigrations(db *gorm.DB) error {
return autoMigrateTables(db, &models.BindRequestDetailsV1{})
}

migrations[16] = func() error {
return autoMigrateTables(db, &models.ServiceInstanceDetailsV4{})
}

var lastMigrationNumber = -1

// if we've run any migrations before, we should have a migrations table, so find the last one we ran
Expand Down
2 changes: 1 addition & 1 deletion dbservice/models/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
type ServiceBindingCredentials ServiceBindingCredentialsV2

// ServiceInstanceDetails holds information about provisioned services.
type ServiceInstanceDetails ServiceInstanceDetailsV3
type ServiceInstanceDetails ServiceInstanceDetailsV4

// ProvisionRequestDetails holds user-defined properties passed to a call
// to provision a service.
Expand Down
34 changes: 34 additions & 0 deletions dbservice/models/historical_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,40 @@ func (ServiceInstanceDetailsV3) TableName() string {
return "service_instance_details"
}

// ServiceInstanceDetailsV4 holds information about provisioned services.
type ServiceInstanceDetailsV4 struct {
ID string `gorm:"primary_key;type:varchar(255);not null"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time

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

ServiceID string
PlanID string
SpaceGUID string
OrganizationGUID string

// OperationType holds a string corresponding to what kind of operation
// OperationID is referencing. The object is "locked" for editing if
// an operation is pending.
OperationType string

// OperationID holds a string referencing an operation specific to a broker.
// Operations in GCP all have a unique ID.
// The OperationID will be cleared after a successful operation.
// This string MAY be sent to users and MUST NOT leak confidential information.
OperationID string `gorm:"type:varchar(1024)"`
}

// TableName returns a consistent table name for
// gorm so multiple structs from different versions of the database all operate
// on the same table.
func (ServiceInstanceDetailsV4) TableName() string {
return "service_instance_details"
}

// ProvisionRequestDetailsV1 holds user-defined properties passed to a call
// to provision a service.
type ProvisionRequestDetailsV1 struct {
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 @@ -33,8 +31,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 @@ -88,8 +84,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 @@ -31,8 +29,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 Down Expand Up @@ -60,8 +56,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 @@ -76,8 +70,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 @@ -99,8 +91,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 @@ -204,8 +194,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 @@ -217,8 +205,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 @@ -230,8 +216,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 4286395

Please sign in to comment.