Skip to content

Commit

Permalink
init db in code,upgrade go chassis
Browse files Browse the repository at this point in the history
  • Loading branch information
tianxiaoliang committed Aug 26, 2020
1 parent 81cc58c commit 83dedac
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions deployments/db.js
Expand Up @@ -121,6 +121,7 @@ db.label.createIndex({"id": 1}, { unique: true } );
db.label.createIndex({format: 1,domain:1,project:1},{ unique: true });
db.polling_detail.createIndex({"id": 1}, { unique: true } );
db.polling_detail.createIndex({session_id:1,domain:1}, { unique: true } );
db.counter.createIndex({name: 1,domain:1},{ unique: true });
db.view.createIndex({"id": 1}, { unique: true } );
db.view.createIndex({display:1,domain:1,project:1},{ unique: true });
//db config
Expand Down
15 changes: 6 additions & 9 deletions examples/dev/conf/chassis.yaml
@@ -1,9 +1,8 @@
---
cse:
service:
registry:
disabled: true
address: http://127.0.0.1:30100
servicecomb:
registry:
disabled: true
address: http://127.0.0.1:30100
protocols:
rest:
listenAddress: 127.0.0.1:30110
Expand All @@ -18,10 +17,8 @@ cse:
rest: 32768 #32K
timeout:
rest: 60s
servicecomb:
service:
quota:
plugin: build-in
quota:
plugin: build-in
# ssl:
# Provider.cipherPlugin: default
# Provider.verifyPeer: false
Expand Down
7 changes: 4 additions & 3 deletions examples/dev/conf/microservice.yaml
@@ -1,4 +1,5 @@
---
service_description:
name: servicecomb-kie
version: 0.1.0
servicecomb:
service:
name: servicecomb-kie
version: 0.1.0
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -4,7 +4,7 @@ require (
github.com/apache/servicecomb-service-center v0.0.0-20200817025835-7bb8c4eb9421
github.com/emicklei/go-restful v2.12.0+incompatible
github.com/go-chassis/go-archaius v1.3.2
github.com/go-chassis/go-chassis v0.0.0-20200818014813-890265d94a1c
github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10
github.com/go-chassis/paas-lager v1.1.1
github.com/go-mesh/openlogging v1.0.1
github.com/go-playground/universal-translator v0.17.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -81,6 +81,8 @@ github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NB
github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4 h1:wx8JXvg/n4i8acXsBJ5zIkiK7EO2kn/HuEjKK3kSgv8=
github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3 h1:c+bwT0qLY69jSU8TmzuNcb9UL/QFAiU96kjuX5TMiQc=
github.com/go-chassis/foundation v0.1.1-0.20200825060850-b16bf420f7b3/go.mod h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c h1:pimEM4Oy/Uf4xG4G7TrRUQbIRFAfHiarxDQQS2gmKaM=
github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c/go.mod h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM=
github.com/go-chassis/go-archaius v1.2.1/go.mod h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM=
Expand Down Expand Up @@ -110,6 +112,8 @@ github.com/go-chassis/go-chassis v0.0.0-20200817095942-bf386412b79e h1:OElheBuqH
github.com/go-chassis/go-chassis v0.0.0-20200817095942-bf386412b79e/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g=
github.com/go-chassis/go-chassis v0.0.0-20200818014813-890265d94a1c h1:aAokQ5cgL/6a8tJsj3W6qr7M3EBoMs3MzlfYqalLLto=
github.com/go-chassis/go-chassis v0.0.0-20200818014813-890265d94a1c/go.mod h1:nMWwWrgDEyDKnMQLE5Gt65RdwbgrQg5amt4BqNFY09g=
github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10 h1:eImN6UFx4pksyxJQnT1laHoVOwSlhEC1ONhJQc4Ix08=
github.com/go-chassis/go-chassis v0.0.0-20200826064053-d90be848aa10/go.mod h1:ZzLCaQFgFHbkwf8grJrbzBLlE19iz+4LMgNtjGlnanU=
github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0 h1:YD9MtuYIpQb+EKxIzV/swdXUhnV5PtXtSW696JiwW1c=
github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0/go.mod h1:sFnVxSvprpy6umPFK4uSdfCDdfqdgbp3FdW/CG0VNnE=
github.com/go-chassis/go-chassis v1.8.2-0.20200331092516-8cf0b374128b h1:AvZjvPQdla1KoLrxbU8bohR3Y9FYnScZFY5KnK2HnSU=
Expand Down
44 changes: 33 additions & 11 deletions server/service/mongo/session/session.go
Expand Up @@ -136,6 +136,7 @@ func Init() error {
})

})
InitDB()
return nil
}

Expand Down Expand Up @@ -191,23 +192,19 @@ func GetColInfo(ctx context.Context, name string) (*CollectionInfo, error) {
return nil, ErrGetPipeline
}

//InitMongodb get collection info
func InitMongodb() {
//InitDB build mongo db schema
func InitDB() {
session, err := mgo.Dial(config.GetDB().URI)
if err != nil {
panic(err)
openlogging.Fatal("can not dial db:" + err.Error())
}
defer session.Close()
session.SetMode(mgo.Monotonic, true)
//counter
c := session.DB(DBName).C(CollectionCounter)
docs := map[string]interface{}{"name": "revision_counter", "count": 1, "domain": "default"}
err = c.Insert(docs)
if err != nil {
panic(err)
}

ensureRevisionCounter(session)

//kv
c = session.DB(DBName).C("kv")
c := session.DB(DBName).C("kv")
err = c.Create(&mgo.CollectionInfo{Validator: bson.M{
"key": bson.M{"$exists": true},
"domain": bson.M{"$exists": true},
Expand Down Expand Up @@ -282,4 +279,29 @@ func InitMongodb() {
if err != nil {
panic(err)
}

}

func ensureRevisionCounter(session *mgo.Session) {
c := session.DB(DBName).C(CollectionCounter)
err := c.Create(&mgo.CollectionInfo{Validator: bson.M{
"name": bson.M{"$exists": true},
"domain": bson.M{"$exists": true},
"count": bson.M{"$exists": true},
}})
if err != nil {
openlogging.Info(err.Error())
}
err = c.EnsureIndex(mgo.Index{
Key: []string{"name", "domain"},
Unique: true,
})
if err != nil {
openlogging.Info(err.Error())
}
docs := map[string]interface{}{"name": "revision_counter", "count": 1, "domain": "default"}
err = c.Insert(docs)
if err != nil {
openlogging.Info(err.Error())
}
}

0 comments on commit 83dedac

Please sign in to comment.