Skip to content

Commit

Permalink
Add Tokens to table Referentials
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard Maffert committed Jun 27, 2017
1 parent 30ed6a9 commit 502247e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/referential.go
Expand Up @@ -314,6 +314,7 @@ func (manager *MemoryReferentials) Load() error {
Referential_id string
Slug string
Settings sql.NullString
Tokens sql.NullString
}

_, err := model.Database.Select(&selectReferentials, "select * from referentials")
Expand All @@ -332,6 +333,12 @@ func (manager *MemoryReferentials) Load() error {
}
}

if r.Tokens.Valid && len(r.Tokens.String) > 0 {
if err = json.Unmarshal([]byte(r.Tokens.String), &referential.Tokens); err != nil {
return err
}
}

manager.Save(referential)
referential.Load()
}
Expand Down
5 changes: 5 additions & 0 deletions core/referential_test.go
Expand Up @@ -279,10 +279,12 @@ func Test_MemoryReferentials_Load(t *testing.T) {
Referential_id string `db:"referential_id"`
Slug string `db:"slug"`
Settings string `db:"settings"`
Tokens string `db:"tokens"`
}{
Referential_id: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
Slug: "ratp",
Settings: "{ \"test.key\": \"test-value\" }",
Tokens: "[\"apiToken\"]",
}

model.Database.AddTableWithName(databaseReferential, "referentials")
Expand Down Expand Up @@ -313,4 +315,7 @@ func Test_MemoryReferentials_Load(t *testing.T) {
if expected := "ratp"; referential.Slug() != ReferentialSlug(expected) {
t.Errorf("Wrong Slug:\n got: %v\n expected: %v", referential.Slug(), expected)
}
if expected := "apiToken"; len(referential.Tokens) != 1 || referential.Tokens[0] != expected {
t.Errorf("Wrong Tokens:\n got: %v\n expected: %v", referential.Tokens, expected)
}
}
11 changes: 11 additions & 0 deletions db/migrations/1498570485.sql
@@ -0,0 +1,11 @@
-- +migrate Up
-- SQL in section 'Up' is executed when this migration is applied

ALTER TABLE referentials
ADD COLUMN tokens text;

-- +migrate Down
-- SQL section 'Down' is executed when this migration is rolled back

ALTER TABLE referentials
DROP COLUMN IF EXISTS tokens;

0 comments on commit 502247e

Please sign in to comment.