Skip to content

Commit 02f26c7

Browse files
committed
Set Routable to true for existing LRPs in Running state
1 parent 4a1f50e commit 02f26c7

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

db/migrations/1686692176_add_routable_to_actual_lrps.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,25 @@ func (e *AddRoutableToActualLrps) SetClock(c clock.Clock) { e.clock = c }
4242
func (e *AddRoutableToActualLrps) SetDBFlavor(flavor string) { e.dbFlavor = flavor }
4343

4444
func (e *AddRoutableToActualLrps) Up(logger lager.Logger) error {
45-
logger.Info("altering the table", lager.Data{"query": alterActualLRPAddRoutableSQL})
46-
_, err := e.rawSQLDB.Exec(alterActualLRPAddRoutableSQL)
47-
if err != nil {
48-
logger.Error("failed-altering-tables", err)
49-
return err
45+
var alterTablesSQL = []string{
46+
alterActualLRPAddRoutableSQL,
47+
alterActualLRPSetRoutableForRunningSQL,
48+
}
49+
for _, query := range alterTablesSQL {
50+
logger.Info("altering the table", lager.Data{"query": query})
51+
_, err := e.rawSQLDB.Exec(query)
52+
if err != nil {
53+
logger.Error("failed-altering-tables", err)
54+
return err
55+
}
56+
logger.Info("altered the table", lager.Data{"query": query})
5057
}
51-
logger.Info("altered the table", lager.Data{"query": alterActualLRPAddRoutableSQL})
5258

5359
return nil
5460
}
5561

5662
const alterActualLRPAddRoutableSQL = `ALTER TABLE actual_lrps
5763
ADD COLUMN routable BOOL DEFAULT false;`
64+
65+
const alterActualLRPSetRoutableForRunningSQL = `UPDATE actual_lrps
66+
SET routable = true WHERE state = 'RUNNING';`

db/migrations/1686692176_add_routable_to_actual_lrps_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var _ = Describe("AddRoutableToActualLrps", func() {
6464
Expect(routable).To(BeTrue())
6565
})
6666

67-
It("sets routable false for all existing actual_lrp rows", func() {
67+
It("sets routable true for all existing actual_lrp rows in RUNNING state", func() {
6868
_, err := rawSQLDB.Exec(
6969
helpers.RebindForFlavor(
7070
`INSERT INTO actual_lrps
@@ -79,6 +79,28 @@ var _ = Describe("AddRoutableToActualLrps", func() {
7979

8080
Expect(migration.Up(logger)).To(Succeed())
8181

82+
var routable bool
83+
query := helpers.RebindForFlavor("select routable from actual_lrps limit 1", flavor)
84+
row := rawSQLDB.QueryRow(query)
85+
Expect(row.Scan(&routable)).To(Succeed())
86+
Expect(routable).To(BeTrue())
87+
})
88+
89+
It("sets routable false for all existing actual_lrp rows not in RUNNING state", func() {
90+
_, err := rawSQLDB.Exec(
91+
helpers.RebindForFlavor(
92+
`INSERT INTO actual_lrps
93+
(process_guid, instance_index, domain, state, net_info,
94+
modification_tag_epoch, modification_tag_index)
95+
VALUES (?, ?, ?, ?, ?, ?, ?)`,
96+
flavor,
97+
),
98+
"guid-1", 10, "cfapps", "CLAIMED", "", "epoch", 0,
99+
)
100+
Expect(err).NotTo(HaveOccurred())
101+
102+
Expect(migration.Up(logger)).To(Succeed())
103+
82104
var routable bool
83105
query := helpers.RebindForFlavor("select routable from actual_lrps limit 1", flavor)
84106
row := rawSQLDB.QueryRow(query)

0 commit comments

Comments
 (0)