diff --git a/internal/fabric/offchain/db.go b/internal/fabric/offchain/db.go index d60b235..27f0e63 100644 --- a/internal/fabric/offchain/db.go +++ b/internal/fabric/offchain/db.go @@ -1,6 +1,7 @@ package offchain import ( + "errors" "fmt" "github.com/Cealgull/Middleware/internal/config" @@ -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{