Skip to content

Commit 20d7e4b

Browse files
sosyzLinkinStars
authored andcommitted
feat(plugin): add key-value storage support for plugins
1 parent 3f1ed50 commit 20d7e4b

6 files changed

Lines changed: 395 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package entity
21+
22+
type PluginKVStorage struct {
23+
ID int `xorm:"not null pk autoincr INT(11) id"`
24+
PluginSlugName string `xorm:"not null VARCHAR(128) UNIQUE(uk_psg) plugin_slug_name"`
25+
Group string `xorm:"not null VARCHAR(128) UNIQUE(uk_psg) 'group'"`
26+
Key string `xorm:"not null VARCHAR(128) UNIQUE(uk_psg) 'key'"`
27+
Value string `xorm:"not null TEXT value"`
28+
}
29+
30+
func (PluginKVStorage) TableName() string {
31+
return "plugin_kv_storage"
32+
}

internal/migrations/init_data.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ var (
7474
&entity.Badge{},
7575
&entity.BadgeGroup{},
7676
&entity.BadgeAward{},
77+
&entity.PluginKVStorage{},
7778
}
7879

7980
roles = []*entity.Role{

internal/migrations/migrations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ var migrations = []Migration{
101101
NewMigration("v1.4.1", "add question link", addQuestionLink, true),
102102
NewMigration("v1.4.2", "add the number of question links", addQuestionLinkedCount, true),
103103
NewMigration("v1.4.5", "add file record", addFileRecord, true),
104+
NewMigration("v1.4.6", "add plugin kv storage", addPluginKVStorage, true),
104105
}
105106

106107
func GetMigrations() []Migration {

internal/service/plugin_common/plugin_common_service.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ func (ps *PluginCommonService) GetUserPluginConfig(ctx context.Context, req *sch
135135
}
136136

137137
func (ps *PluginCommonService) initPluginData() {
138+
plugin.SetKVStorageDB(&plugin.Data{
139+
DB: ps.data.DB,
140+
Cache: ps.data.Cache,
141+
})
142+
138143
// init plugin status
139144
pluginStatus, err := ps.configService.GetStringValue(context.TODO(), constant.PluginStatus)
140145
if err != nil {

0 commit comments

Comments
 (0)