@@ -30,33 +30,55 @@ func (i ItemType) String() string {
30
30
return string (i )
31
31
}
32
32
33
+ // ShareID only contains IDs of shares and public links. This is because OCIS requires
34
+ // that shares and public links do not share an ID, so we need a shared table to make sure
35
+ // that there are no duplicates.
36
+ // This is implemented by having ShareID have an ID that is auto-increment, and shares and
37
+ // public links will have their ID be a foreign key to ShareID
38
+ // When creating a new share, we will then first create an ID entry and use this for the ID
39
+
40
+ type ShareID struct {
41
+ ID uint `gorm:"primarykey"`
42
+ }
43
+
44
+ // We cannot use gorm.Model, because we want our ID to be a foreign key to ShareID
45
+ type BaseModel struct {
46
+ // Id has to be called Id and not ID, otherwise the foreign key will not work
47
+ // ID is a special field in GORM, which it uses as the default Primary Key
48
+ Id uint `gorm:"uniqueIndex"`
49
+ ShareId ShareID `gorm:"foreignKey:Id;references:ID;constraint:OnDelete:CASCADE"` //;references:ID
50
+ CreatedAt time.Time
51
+ UpdatedAt time.Time
52
+ DeletedAt gorm.DeletedAt `gorm:"index"`
53
+ }
54
+
33
55
// ProtoShare contains fields that are shared between PublicLinks and Shares.
34
56
// Unfortunately, because these are shared, we cannot name our indexes
35
57
// because then two indexes with the same name would be created
36
58
type ProtoShare struct {
37
59
// Including gorm.Model will embed a number of gorm-default fields
38
- gorm. Model
60
+ BaseModel
39
61
UIDOwner string `gorm:"size:64"`
40
62
UIDInitiator string `gorm:"size:64"`
41
63
ItemType ItemType `gorm:"size:16;index:"` // file | folder | reference | symlink
42
64
InitialPath string
43
- Inode string `gorm:"size:32;index:"`
44
- Instance string `gorm:"size:32;index:"`
65
+ Inode string `gorm:"primaryKey; size:32;index:"`
66
+ Instance string `gorm:"primaryKey; size:32;index:"`
45
67
Permissions uint8
46
68
Orphan bool
47
69
Expiration datatypes.NullTime
48
70
}
49
71
50
72
type Share struct {
51
73
ProtoShare
52
- ShareWith string `gorm:"size:255;index:i_share_with"` // 255 because this can be a lw account, which are mapped from email addresses / ...
74
+ ShareWith string `gorm:"primaryKey; size:255;index:i_share_with"` // 255 because this can be a lw account, which are mapped from email addresses / ...
53
75
SharedWithIsGroup bool
54
76
Description string `gorm:"size:1024"`
55
77
}
56
78
57
79
type PublicLink struct {
58
80
ProtoShare
59
- Token string `gorm:"index:i_token"`
81
+ Token string `gorm:"primaryKey; index:i_token"`
60
82
// Enforce uniqueness in db re: Itemsource
61
83
Quicklink bool
62
84
NotifyUploads bool
@@ -68,8 +90,8 @@ type PublicLink struct {
68
90
69
91
type ShareState struct {
70
92
gorm.Model
71
- ShareID uint `gorm:"foreignKey:ShareID;references:ID; uniqueIndex:i_shareid_user"` // Define the foreign key field
72
- Share Share // Define the association
93
+ ShareID uint `gorm:"uniqueIndex:i_shareid_user"` // Define the foreign key field
94
+ Share Share `gorm:"foreignKey:ShareID;references:Id"` // Define the association
73
95
// Can not be uid because of lw accs
74
96
User string `gorm:"uniqueIndex:i_shareid_user;size:255"`
75
97
Synced bool
@@ -86,7 +108,7 @@ func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share {
86
108
}
87
109
return & collaboration.Share {
88
110
Id : & collaboration.ShareId {
89
- OpaqueId : strconv .FormatUint (uint64 (s .ID ), 10 ),
111
+ OpaqueId : strconv .FormatUint (uint64 (s .Id ), 10 ),
90
112
},
91
113
//ResourceId: &provider.Reference{StorageId: s.Prefix, NodeId: s.ItemSource},
92
114
ResourceId : & provider.ResourceId {
@@ -139,7 +161,7 @@ func (p *PublicLink) AsCS3PublicShare() *link.PublicShare {
139
161
}
140
162
return & link.PublicShare {
141
163
Id : & link.PublicShareId {
142
- OpaqueId : strconv .Itoa (int (p .ID )),
164
+ OpaqueId : strconv .Itoa (int (p .Id )),
143
165
},
144
166
ResourceId : & provider.ResourceId {
145
167
StorageId : p .Instance ,
0 commit comments