-
-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(schedule): replace disabled field to active
- Loading branch information
Showing
8 changed files
with
95 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package bolt | ||
|
||
type migration_2_10_12 struct { | ||
migration | ||
} | ||
|
||
func (d migration_2_10_12) Apply() error { | ||
projectIDs, err := d.getProjectIDs() | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, projectID := range projectIDs { | ||
schedules, err := d.getObjects(projectID, "schedule") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for scheduleID, schedule := range schedules { | ||
schedule["active"] = true | ||
err = d.setObject(projectID, "schedule", scheduleID, schedule) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package bolt | ||
|
||
import ( | ||
"encoding/json" | ||
"go.etcd.io/bbolt" | ||
"testing" | ||
) | ||
|
||
func TestMigration_2_10_12_Apply(t *testing.T) { | ||
store := CreateTestStore() | ||
|
||
err := store.db.Update(func(tx *bbolt.Tx) error { | ||
b, err := tx.CreateBucketIfNotExists([]byte("project")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = b.Put([]byte("0000000001"), []byte("{}")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r, err := tx.CreateBucketIfNotExists([]byte("project__schedule_0000000001")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = r.Put([]byte("0000000001"), | ||
[]byte("{\"id\":\"1\",\"project_id\":\"1\"}")) | ||
|
||
return err | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
err = migration_2_10_12{migration{store.db}}.Apply() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
var scheduleData map[string]interface{} | ||
err = store.db.View(func(tx *bbolt.Tx) error { | ||
b := tx.Bucket([]byte("project__schedule_0000000001")) | ||
str := string(b.Get([]byte("0000000001"))) | ||
return json.Unmarshal([]byte(str), &scheduleData) | ||
}) | ||
|
||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !scheduleData["active"].(bool) { | ||
t.Fatal("invalid role") | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
db/sql/migrations/v2.10.11.sql → db/sql/migrations/v2.10.12.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
alter table `project__template` add `tasks` int not null default 0; | ||
alter table `project__schedule` add `name` varchar(100); | ||
alter table `project__schedule` add `disabled` boolean not null default false; | ||
alter table `project__schedule` add `active` boolean not null default true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters