fix: vfs node primary id not generated properly

This commit is contained in:
2025-11-30 19:20:08 +00:00
parent 1907cd83c8
commit a3110b67c3
2 changed files with 20 additions and 4 deletions

View File

@@ -28,18 +28,22 @@ type Node struct {
ID uuid.UUID `bun:",pk,type:uuid"` ID uuid.UUID `bun:",pk,type:uuid"`
PublicID string `bun:"public_id,notnull"` PublicID string `bun:"public_id,notnull"`
AccountID uuid.UUID `bun:"account_id,notnull,type:uuid"` AccountID uuid.UUID `bun:"account_id,notnull,type:uuid"`
ParentID uuid.UUID `bun:"parent_id"` ParentID uuid.UUID `bun:"parent_id,nullzero"`
Kind NodeKind `bun:"kind,notnull"` Kind NodeKind `bun:"kind,notnull"`
Status NodeStatus `bun:"status,notnull"` Status NodeStatus `bun:"status,notnull"`
Name string `bun:"name,notnull"` Name string `bun:"name,notnull"`
BlobKey blob.Key `bun:"blob_key"` BlobKey blob.Key `bun:"blob_key,nullzero"`
Size int64 `bun:"size"` Size int64 `bun:"size"`
MimeType string `bun:"mime_type"` MimeType string `bun:"mime_type,nullzero"`
CreatedAt time.Time `bun:"created_at,notnull,nullzero"` CreatedAt time.Time `bun:"created_at,notnull,nullzero"`
UpdatedAt time.Time `bun:"updated_at,notnull,nullzero"` UpdatedAt time.Time `bun:"updated_at,notnull,nullzero"`
DeletedAt time.Time `bun:"deleted_at"` DeletedAt time.Time `bun:"deleted_at,nullzero"`
}
func newNodeID() (uuid.UUID, error) {
return uuid.NewV7()
} }
// IsAccessible returns true if the node can be accessed. // IsAccessible returns true if the node can be accessed.

View File

@@ -125,7 +125,13 @@ func (vfs *VirtualFS) CreateFile(ctx context.Context, db bun.IDB, accountID uuid
return nil, err return nil, err
} }
id, err := newNodeID()
if err != nil {
return nil, err
}
node := Node{ node := Node{
ID: id,
PublicID: pid, PublicID: pid,
AccountID: accountID, AccountID: accountID,
ParentID: opts.ParentID, ParentID: opts.ParentID,
@@ -239,7 +245,13 @@ func (vfs *VirtualFS) CreateDirectory(ctx context.Context, db bun.IDB, accountID
return nil, err return nil, err
} }
id, err := newNodeID()
if err != nil {
return nil, err
}
node := Node{ node := Node{
ID: id,
PublicID: pid, PublicID: pid,
AccountID: accountID, AccountID: accountID,
ParentID: parentID, ParentID: parentID,