Completed db rewrite
This commit is contained in:
parent
54d7d14ef9
commit
cf4b8e0119
19 changed files with 481 additions and 276 deletions
|
|
@ -3,64 +3,52 @@ package core
|
|||
import "github.com/shopspring/decimal"
|
||||
|
||||
type User struct {
|
||||
Username string `gorm:"primaryKey" json:"username"`
|
||||
Password string `json:"password"`
|
||||
OwnedPlans []Plan `gorm:"foreignKey:Owner;references:Username" json:"-"`
|
||||
MemberOf []Member `json:"-"`
|
||||
Votes []Vote `gorm:"foreignKey:UsernameID" json:"-"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
}
|
||||
|
||||
type Member struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"-"`
|
||||
PlanID uint `json:"-"`
|
||||
Plan Plan `json:"-"`
|
||||
Name string `gorm:"check:user_id IS NOT NULL OR name IS NOT NULL" json:"name,omitempty"`
|
||||
UserID string `json:"username,omitempty"`
|
||||
User User `gorm:"foreignKey:UserID" json:"-"`
|
||||
Id uint `json:"-"`
|
||||
PlanId uint `json:"-"`
|
||||
Name string `json:"name,omitempty"`
|
||||
UserId *string `json:"username,omitempty"`
|
||||
}
|
||||
|
||||
// CREATE TABLE plans(id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING, owner STRING, FOREIGN KEY(owner) REFERENCES users(username))
|
||||
// CREATE TABLE plan_user_relations(username STRING, plan INTEGER, PRIMARY KEY(username, plan), FOREIGN KEY username REFERENCES user(username), FOREIGN KEY plan REFERENCES plans(id))
|
||||
type Plan struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
Name string `json:"name"`
|
||||
Owner string `json:"owner"`
|
||||
Description string `json:"description"`
|
||||
JoinCode string `gorm:"not null" json:"join_code,omitempty"`
|
||||
Members []Member `json:"-"`
|
||||
Polls []Poll `gorm:"foreignKey:PlanID;references:ID" json:"-"`
|
||||
Id uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Owner string `json:"owner"`
|
||||
Description string `json:"description"`
|
||||
JoinCode string `json:"join_code,omitempty"`
|
||||
}
|
||||
|
||||
type Expense struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
PlanID uint `json:"-"`
|
||||
Plan Plan `json:"-"`
|
||||
PayerID uint `json:"-"`
|
||||
Payer Member `gorm:"foreignKey:PayerID" json:"-"`
|
||||
Id uint `json:"id"`
|
||||
PlanId uint `json:"-"`
|
||||
PayerId uint `json:"-"`
|
||||
Amount decimal.Decimal `json:"amount"`
|
||||
Debts []Debt `gorm:"foreignKey:ExpenseID" json:"debts,omitempty"`
|
||||
}
|
||||
|
||||
type Debt struct {
|
||||
ExpenseID uint `gorm:"primaryKey" json:"-"`
|
||||
Expense Expense `gorm:"foreignKey:ExpenseID"`
|
||||
DebtorID uint `gorm:"primaryKey" json:"-"`
|
||||
Debtor Member `gorm:"foreignKey:DebtorID"`
|
||||
Id uint
|
||||
ExpenseId uint `json:"-"`
|
||||
DebtorId uint `json:"-"`
|
||||
Amount decimal.Decimal
|
||||
Paid decimal.Decimal
|
||||
}
|
||||
|
||||
// CREATE TABLE polls(id INTEGER PRIMARY KEY AUTOINCREMENT, plan INTEGER, name STRING, options JSON, FOREIGN KEY plan REFERENCES plans(id))
|
||||
type Poll struct {
|
||||
ID uint `gorm:"primaryKey;autoIncrement:true" json:"id"`
|
||||
PlanID uint `json:"-"`
|
||||
Id uint `json:"id"`
|
||||
PlanId uint `json:"-"`
|
||||
Options string `json:"options"`
|
||||
Votes []Vote `gorm:"foreignKey:PollID;references:ID" json:"-"`
|
||||
}
|
||||
|
||||
// CREATE TABLE votes(id INTEGER, poll INTEGER, user STRING, value JSON, FOREIGN KEY poll REFERENCES polls(id), FOREIGN KEY user REFERENCES user(username))
|
||||
type Vote struct {
|
||||
PollID uint `gorm:"primaryKey" json:"-"`
|
||||
UsernameID string `gorm:"primaryKey" json:"username_id"`
|
||||
Value string `json:"value"`
|
||||
PollId uint `json:"-"`
|
||||
MemberId uint `json:"member_id"`
|
||||
Value string `json:"value"`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue