@@ -30,33 +30,53 @@ 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
+ MyID uint `gorm:"uniqueIndex;autoIncrement:false"`
47
+ ShareId ShareID `gorm:"foreignKey:MyID;references:ID;constraint:OnDelete:CASCADE"` //;references:ID
48
+ CreatedAt time.Time
49
+ UpdatedAt time.Time
50
+ DeletedAt gorm.DeletedAt `gorm:"index"`
51
+ }
52
+
33
53
// ProtoShare contains fields that are shared between PublicLinks and Shares.
34
54
// Unfortunately, because these are shared, we cannot name our indexes
35
55
// because then two indexes with the same name would be created
36
56
type ProtoShare struct {
37
57
// Including gorm.Model will embed a number of gorm-default fields
38
- gorm. Model
58
+ BaseModel
39
59
UIDOwner string `gorm:"size:64"`
40
60
UIDInitiator string `gorm:"size:64"`
41
61
ItemType ItemType `gorm:"size:16;index:"` // file | folder | reference | symlink
42
62
InitialPath string
43
- Inode string `gorm:"size:32;index:"`
44
- Instance string `gorm:"size:32;index:"`
63
+ Inode string `gorm:"primaryKey; size:32;index:"`
64
+ Instance string `gorm:"primaryKey; size:32;index:"`
45
65
Permissions uint8
46
66
Orphan bool
47
67
Expiration datatypes.NullTime
48
68
}
49
69
50
70
type Share struct {
51
71
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 / ...
72
+ 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
73
SharedWithIsGroup bool
54
74
Description string `gorm:"size:1024"`
55
75
}
56
76
57
77
type PublicLink struct {
58
78
ProtoShare
59
- Token string `gorm:"index:i_token"`
79
+ Token string `gorm:"primaryKey; index:i_token"`
60
80
// Enforce uniqueness in db re: Itemsource
61
81
Quicklink bool
62
82
NotifyUploads bool
@@ -68,8 +88,8 @@ type PublicLink struct {
68
88
69
89
type ShareState struct {
70
90
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
91
+ ShareID uint `gorm:"uniqueIndex:i_shareid_user"` // Define the foreign key field
92
+ Share Share `gorm:"foreignKey:ShareID;references:ID"` // Define the association
73
93
// Can not be uid because of lw accs
74
94
User string `gorm:"uniqueIndex:i_shareid_user;size:255"`
75
95
Synced bool
@@ -86,7 +106,7 @@ func (s *Share) AsCS3Share(granteeType userpb.UserType) *collaboration.Share {
86
106
}
87
107
return & collaboration.Share {
88
108
Id : & collaboration.ShareId {
89
- OpaqueId : strconv .FormatUint (uint64 (s .ID ), 10 ),
109
+ OpaqueId : strconv .FormatUint (uint64 (s .MyID ), 10 ),
90
110
},
91
111
//ResourceId: &provider.Reference{StorageId: s.Prefix, NodeId: s.ItemSource},
92
112
ResourceId : & provider.ResourceId {
@@ -139,7 +159,7 @@ func (p *PublicLink) AsCS3PublicShare() *link.PublicShare {
139
159
}
140
160
return & link.PublicShare {
141
161
Id : & link.PublicShareId {
142
- OpaqueId : strconv .Itoa (int (p .ID )),
162
+ OpaqueId : strconv .Itoa (int (p .MyID )),
143
163
},
144
164
ResourceId : & provider.ResourceId {
145
165
StorageId : p .Instance ,
0 commit comments