/
models.go
149 lines (130 loc) · 5.94 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (c) 2017-2019 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package cockroachdb
import (
"time"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
// Version describes the version of a record or plugin that the database is
// currently using.
type Version struct {
ID string `gorm:"primary_key"` // Primary key
Version string `gorm:"not null"` // Version
Timestamp int64 `gorm:"not null"` // UNIX timestamp of record creation
}
// TableName returns the table name of the invoices table.
func (Version) TableName() string {
return tableNameVersions
}
// Invoice is the database model for the database.Invoice type
type Invoice struct {
Key string `gorm:"primary_key"` // Token + version
Token string `gorm:"not null"`
UserID string `gorm:"not null"`
Username string `gorm:"-"` // Only populated when reading from the database
Month uint `gorm:"not null"`
Year uint `gorm:"not null"`
ExchangeRate uint `gorm:"not null"`
Timestamp time.Time `gorm:"not null"`
Status uint `gorm:"not null"`
StatusChangeReason string `gorm:"not null"`
PublicKey string `gorm:"not null"`
UserSignature string `gorm:"not null"`
ServerSignature string `gorm:"not null"`
Version string `gorm:"not null"`
ContractorName string `gorm:"not null"`
ContractorLocation string `gorm:"not null"`
ContractorRate uint `gorm:"not null"`
ContractorContact string `gorm:"not null"`
PaymentAddress string `gorm:"not null"`
LineItems []LineItem `gorm:"foreignkey:InvoiceKey"`
Changes []InvoiceChange `gorm:"foreignkey:InvoiceKey"`
Payments Payments `gorm:"foreignkey:InvoiceKey"`
}
// TableName returns the table name of the invoices table.
func (Invoice) TableName() string {
return tableNameInvoice
}
// LineItem is the database model for the database.LineItem type
type LineItem struct {
LineItemKey string `gorm:"primary_key"` // Token of the Invoice + version + array index
InvoiceKey string `gorm:"not null"` // The key of the invoice that it is attached
InvoiceToken string `gorm:"not null"` // Censorship token of the invoice
Type uint `gorm:"not null"` // Type of line item
Domain string `gorm:"not null"` // Domain of the work performed (dev, marketing etc)
Subdomain string `gorm:"not null"` // Subdomain of the work performed (decrediton, event X etc)
Description string `gorm:"not null"` // Description of work performed
ProposalURL string `gorm:"not null"` // Link to politeia proposal that work is associated with
Labor uint `gorm:"not null"` // Number of minutes worked
Expenses uint `gorm:"not null"` // Total cost of line item (in USD cents)
ContractorRate uint `gorm:"not null"` // Optional contractor rate for line item, typically used for Sub Contractors
SubUserID string `gorm:"not null"` // SubContractor User ID if Subcontractor Line Item
}
// TableName returns the table name of the line items table.
func (LineItem) TableName() string {
return tableNameLineItem
}
// InvoiceChange contains entries for any status update that occurs to a given
// invoice. This will give a full history of an invoices history.
type InvoiceChange struct {
InvoiceKey string `gorm:"not null"` // The key of the invoice that it is attached
InvoiceToken string `gorm:"not null"` // Censorship token of the invoice
AdminPublicKey string `gorm:"not null"` // The public of the admin that processed the status change.
NewStatus uint `gorm:"not null"` // Updated status of the invoice.
Reason string `gorm:"not null"` // Reason for status updated (required if rejected)
Timestamp time.Time `gorm:"not null"` // The timestamp of the status change.
}
// TableName returns the table name of the line items table.
func (InvoiceChange) TableName() string {
return tableNameInvoiceChange
}
// ExchangeRate contains cached calculated rates for a given month/year
type ExchangeRate struct {
Month uint `gorm:"not null"`
Year uint `gorm:"not null"`
ExchangeRate uint `gorm:"not null"`
}
// TableName returns the table name of the line items table.
func (ExchangeRate) TableName() string {
return tableNameExchangeRate
}
// Payments contains all the information about a given invoice's payment
type Payments struct {
InvoiceKey string `gorm:"primary_key"` // The key of the invoice that it is attached
InvoiceToken string `gorm:"not null"`
Address string `gorm:"not null"`
TxIDs string `gorm:"not null"`
TimeStarted int64 `gorm:"not null"`
TimeLastUpdated int64 `gorm:"not null"`
AmountNeeded int64 `gorm:"not null"`
AmountReceived int64 `gorm:"not null"`
Status uint `gorm:"not null"`
}
// TableName returns the table name of the line items table.
func (Payments) TableName() string {
return tableNamePayments
}
// DCC contains all the information about a given DCC proposal.
type DCC struct {
Token string `gorm:"primary_key"`
SponsorUserID string `gorm:"not null"`
NomineeUserID string `gorm:"not null"`
Type int `gorm:"not null"`
Status int `gorm:"not null"`
StatusChangeReason string `gorm:"not null"`
TimeSubmitted int64 `gorm:"not null"`
TimeReviewed int64 `gorm:"not null"`
PublicKey string `gorm:"not null"`
UserSignature string `gorm:"not null"`
ServerSignature string `gorm:"not null"`
SponsorStatement string `gorm:"not null"`
Domain int `gorm:"not null"`
ContractorType int `gorm:"not null"`
SupportUserIDs string `gorm:"not null"`
OppositionUserIDs string `gorm:"not null"`
}
// TableName returns the table name of the DCC table.
func (DCC) TableName() string {
return tableNameDCC
}