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