Skip to content

Commit

Permalink
chore(db): seed some data
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyang Wu <toolmanp@outlook.com>
  • Loading branch information
ToolmanP committed Sep 9, 2023
1 parent 992fae3 commit e9306ae
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions internal/fabric/offchain/db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package offchain

import (
"errors"
"fmt"

"github.com/Cealgull/Middleware/internal/config"
Expand Down Expand Up @@ -72,6 +73,26 @@ func NewOffchainStore(dialector gorm.Dialector, config *config.PostgresGormConfi
return nil, err
}

if err := db.Model(&User{}).First(&User{}).Error; errors.Is(err, gorm.ErrRecordNotFound) {
wallet := "0x12345678"
var _ = db.Create(&User{Username: "admin", Avatar: "", Wallet: wallet})
var _ = db.Create(&Profile{Signature: "this is a signature", UserWallet: &wallet})
var _ = db.Create(&CategoryGroup{Name: "General", Color: "#E25E3E"})
var _ = db.Create(&Category{CategoryGroupName: "General", Name: "General Discussion", Color: "#E25E3E"})
var _ = db.Create(&Category{CategoryGroupName: "General", Name: "General Topic", Color: "#C63D2F"})
var _ = db.Create(&[]*Tag{{CreatorWallet: "0x12345678", Name: "tag1"},
{CreatorWallet: "0x12345678", Name: "tag2"},
{CreatorWallet: "0x12345678", Name: "tag3"}})
var _ = db.Create(&Topic{Title: "this is a test topic",
Hash: "hash1",
Content: "Genshin Impact is a good game",
CreatorWallet: "0x12345678",
CategoryAssigned: &CategoryRelation{CategoryName: "General Topic"}})
var _ = db.Create(&Post{Hash: "post1Hash", CreatorWallet: "0x12345678", BelongToHash: "hash1", Content: "this is a test post"})
id := uint(1)
var _ = db.Create(&Post{Hash: "post2Hash", CreatorWallet: "0x12345678", BelongToHash: "hash1", Content: "this is a test post", ReplyToID: &id})
}

if config.Prometheus.Enabled {
var _ = db.Use(prometheus.New(
prometheus.Config{
Expand Down

0 comments on commit e9306ae

Please sign in to comment.