github.com/decred/politeia@v1.4.0/politeiawww/legacy/user/cockroachdb/models.go (about) 1 package cockroachdb 2 3 import ( 4 "time" 5 6 "github.com/google/uuid" 7 ) 8 9 // KeyValue store is a generic key-value store. 10 type KeyValue struct { 11 Key string `gorm:"primary_key"` 12 Value []byte `gorm:"not null"` 13 } 14 15 // TableName returns the table name of the KeyValue table. 16 func (KeyValue) TableName() string { 17 return tableKeyValue 18 } 19 20 // Identity represents a user identity. 21 type Identity struct { 22 PublicKey string `gorm:"primary_key;size:64"` // ed25519 public key 23 UserID uuid.UUID `gorm:"not null"` // User UUID (User foreign key) 24 Activated int64 `gorm:"not null"` // UNIX timestamp of activation 25 Deactivated int64 `gorm:"not null"` // UNIX timestamp of deactivation 26 } 27 28 // TableName returns the table name of the Identity table. 29 func (Identity) TableName() string { 30 return tableIdentities 31 } 32 33 // User represents a politeiawww user. Blog is an encrypted blob of the full 34 // user object. 35 type User struct { 36 ID uuid.UUID `gorm:"primary_key"` // UUID 37 Username string `gorm:"not null;unique"` // Unique username 38 Identities []Identity `gorm:"foreignkey:UserID"` // User identity history 39 Blob []byte `gorm:"not null"` // Encrypted blob of user data 40 41 // Set by gorm 42 CreatedAt time.Time // Time of record creation 43 UpdatedAt time.Time // Time of last record update 44 } 45 46 // TableName returns the table name of the User table. 47 func (User) TableName() string { 48 return tableUsers 49 } 50 51 type EmailHistory struct { 52 UserID uuid.UUID `gorm:"primary_key"` // User UUID 53 Blob []byte `gorm:"not null"` // Encrypted email history 54 } 55 56 func (EmailHistory) TableName() string { 57 return tableEmailHistories 58 } 59 60 // Session represents a user session. 61 // 62 // Key is a SHA256 hash of the decoded session ID. The session Store handles 63 // encoding/decoding the ID. 64 // 65 // Blob represents an ecrypted user.Session. The fields that have been broken 66 // out of the encrypted blob are the fields that need to be queryable. 67 type Session struct { 68 Key string `gorm:"primary_key"` // SHA256 hash of the session ID 69 UserID uuid.UUID `gorm:"not null"` // User UUID 70 CreatedAt int64 `gorm:"not null"` // Created at UNIX timestamp 71 Blob []byte `gorm:"not null"` // Encrypted user session 72 } 73 74 // TableName returns the table name of the Session table. 75 func (Session) TableName() string { 76 return tableSessions 77 } 78 79 // CMSUser represents a CMS user. A CMS user includes the politeiawww User 80 // object as well as CMS specific user fields. A CMS user must correspond to 81 // a politeiawww User. 82 // 83 // This is a CMS plugin model. 84 // 85 // XXX We need to update SupervisorUserID to SupervisorUserIDs next time we 86 // update or do any migration on the userdb. 87 type CMSUser struct { 88 ID uuid.UUID `gorm:"primary_key"` // UUID (User foreign key) 89 User User `gorm:"not null;foreignkey:ID"` // politeiawww user 90 Domain int `gorm:"not null"` // Contractor domain 91 GitHubName string `gorm:"not null"` // Github Name/ID 92 MatrixName string `gorm:"not null"` // Matrix Name/ID 93 ContractorType int `gorm:"not null"` // Type of Contractor 94 ContractorName string `gorm:"not null"` // IRL Contractor Name or identity 95 ContractorLocation string `gorm:"not null"` // General IRL Contractor Location 96 ContractorContact string `gorm:"not null"` // Point of contact outside of matrix 97 SupervisorUserID string `gorm:"not null"` // This is can either be 1 SupervisorUserID or a comma separated string of many supervisor user ids 98 ProposalsOwned string `gorm:"not null"` // This can either be 1 Proposal or a comma separated string of many. 99 100 // Set by gorm 101 CreatedAt time.Time // Time of record creation 102 UpdatedAt time.Time // Time of last record update 103 } 104 105 // TableName returns the table name of the CMSUsers table. 106 func (CMSUser) TableName() string { 107 return tableCMSUsers 108 } 109 110 // CMSCodeStats struct contains information per month/year per repo for 111 // a given users' code statistics for merged pull requests and completed 112 // reviews over that time period. 113 type CMSCodeStats struct { 114 ID string `gorm:"primary_key"` // UserID + GithubName + Month + Year 115 GitHubName string `gorm:"not null"` // GithubName 116 Repository string `gorm:"not null"` // Repository 117 Month int `gorm:"not null"` // Month of code stats 118 Year int `gorm:"not null"` // Year of code stats 119 PRs string `gorm:"not null"` // String of all PR URLs separated by commas 120 Reviews string `gorm:"not null"` // String of all Reviewed PR URLS separated by commas 121 Commits string `gorm:"not null"` // String of all commit URL separated by commas 122 MergedAdditions int64 `gorm:"not null"` // Total merged code additions 123 MergedDeletions int64 `gorm:"not null"` // Total merged code deletions 124 UpdatedAdditions int64 `gorm:"not null"` // Total updated code additions 125 UpdatedDeletions int64 `gorm:"not null"` // Total updated code deletions 126 ReviewAdditions int64 `gorm:"not null"` // Total reviewed code additions 127 ReviewDeletions int64 `gorm:"not null"` // Total reviewed code deletions 128 CommitAdditions int64 `gorm:"not null"` // Total commit additions 129 CommitDeletions int64 `gorm:"not null"` // Total commit deletions 130 } 131 132 // TableName returns the table name of the CMSUsers table. 133 func (CMSCodeStats) TableName() string { 134 return tableCMSCodeStats 135 }