package data import ( "fmt" "github.com/spf13/viper" "gorm.io/driver/postgres" "gorm.io/gorm" ) type Bonus struct { Goal float64 `json:"goal"` Percent float64 `json:"percent"` RewardFundID uint `json:"rewardFundID"` } type RewardFund struct { gorm.Model Asset string `json:"asset"` FundWallet string `json:"fundWallet"` FundSecret string `json:"fundSecret"` IssuerWallet string `json:"issuerWallet"` Memo string `json:"memo"` Price float64 `json:"price"` AmountGoal float64 `gorm:"type:decimal(19,7)" json:"amountGoal"` MinContribution float64 `gorm:"type:decimal(19,7)" json:"minContribution"` Contributions []Contribution `json:"contributions"` Title string `gorm:"type:varchar(50)" json:"title"` Description string `gorm:"type:text" json:"description"` Bonuses []Bonus `json:"bonuses"` } type Contribution struct { gorm.Model Wallet string `json:"wallet"` Amount float64 `gorm:"type:decimal(19,7)" json:"amount"` TransactionID string `json:"transactionID"` RewardFundID uint `json:"rewardFundID"` Tags []AppliedTag `json:"tags"` } type Tag struct { gorm.Model Description string `json:"description"` Active bool `json:"active"` Contribution AppliedTag `json:"contribution"` } type AppliedTag struct { gorm.Model TagID uint `json:"tagID"` ContributionID uint `json:"contributionID"` } type User struct { gorm.Model Username string `json:"username"` Password string `json:"password"` Privileges uint `json:"admin"` } var Db *gorm.DB func InitializeDatabase() { var err error dcs := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=%s", viper.GetString("database.host"), viper.GetString("database.user"), viper.GetString("database.password"), viper.GetString("database.name"), viper.GetInt("database.port"), viper.GetString("database.ssl")) Db, err = gorm.Open(postgres.Open(dcs), &gorm.Config{}) err = Db.AutoMigrate(User{}, RewardFund{}, Contribution{}, Bonus{}) if err != nil { panic("Could not migrate database") } }