feat:[AH-628]: File manager framework DB migration and objects (#2954)

* [AH-628]: Renamed files
* Merge branch 'main' of https://git0.harness.io/l7B_kbSEQD2wjrM7PShm5w/PROD/Harness_Commons/gitness into AH-628
* feat:[AH-628]: review changes
* feat:[AH-628]: review changes
* feat:[AH-628]: review changes
* feat:[AH-628]: review changes
* feat:[AH-628]: fix uts
* feat:[AH-628]: fix node object
* feat:[AH-628]: change in DB objects
* feat:[AH-628]: change in DB objects
* feat:[AH-628]: change in DB objects
* Merge branch 'main' into AH-628
* feat:[AH-628]: review changes
* feat:[AH-628]: file manager changes with some DB and swagger changes
* feat:[Ah-628]: File manager framwork migrations
BT-10437
Sourabh Awashti 2024-12-26 19:34:12 +00:00 committed by Harness
parent c54e09908b
commit ea1d934dec
9 changed files with 238 additions and 0 deletions

View File

@ -0,0 +1,3 @@
DROP TABLE IF EXISTS nodes;
DROP TABLE IF EXISTS generic_blob;
DROP TABLE IF EXISTS file_nodes;

View File

@ -0,0 +1,50 @@
create table if not exists nodes
(
node_id TEXT PRIMARY KEY,
node_name text not null,
node_parent_id INTEGER not null,
node_registry_id INTEGER not null
CONSTRAINT fk_registry_registry_id
REFERENCES registries (registry_id) ,
node_created_at BIGINT not null,
node_created_by INTEGER not null,
node_is_file BOOLEAN not null,
node_path text not null,
constraint unique_nodes
unique (node_name, node_parent_id, node_registry_id)
);
create table if not exists generic_blob
(
generic_blob_id TEXT PRIMARY KEY,
generic_blob_root_parent_id INTEGER not null ,
generic_blob_sha_1 TEXT not null,
generic_blob_sha_256 TEXT not null,
generic_blob_sha_512 TEXT not null,
generic_blob_MD5 TEXT not null,
generic_blob_size INTEGER not null,
generic_blob_created_at BIGINT not null,
generic_blob_created_by INTEGER not null,
constraint unique_hash_root_parent_id unique (generic_blob_sha_256, generic_blob_root_parent_id)
);
create table if not exists file_nodes
(
file_node_id TEXT PRIMARY KEY,
file_node_name text not null,
file_node_parent_node_id INTEGER not null
CONSTRAINT fk_node_node_id
REFERENCES nodes(node_id) ,
file_node_generic_blob_id INTEGER not null
CONSTRAINT fk_generic_blob_generic_blob_id
REFERENCES generic_blob(generic_blob_id) ,
file_node_created_at BIGINT not null,
file_node_created_by INTEGER not null,
constraint unique_file_node
unique (file_node_parent_node_id, file_node_name)
);

View File

@ -0,0 +1,3 @@
DROP TABLE IF EXISTS nodes;
DROP TABLE IF EXISTS generic_blob;
DROP TABLE IF EXISTS file_nodes;

View File

@ -0,0 +1,50 @@
create table if not exists nodes
(
node_id TEXT PRIMARY KEY,
node_name text not null,
node_parent_id INTEGER not null,
node_registry_id INTEGER not null
CONSTRAINT fk_registry_registry_id
REFERENCES registries (registry_id) ,
node_created_at BIGINT not null,
node_created_by INTEGER not null,
node_is_file BOOLEAN not null,
node_path text not null,
constraint unique_nodes
unique (node_name, node_parent_id, node_registry_id)
);
create table if not exists generic_blob
(
generic_blob_id TEXT PRIMARY KEY,
generic_blob_root_parent_id INTEGER not null ,
generic_blob_sha_1 TEXT not null,
generic_blob_sha_256 TEXT not null,
generic_blob_sha_512 TEXT not null,
generic_blob_MD5 TEXT not null,
generic_blob_size INTEGER not null,
generic_blob_created_at BIGINT not null,
generic_blob_created_by INTEGER not null,
constraint unique_hash_root_parent_id unique (generic_blob_sha_256, generic_blob_root_parent_id)
);
create table if not exists file_nodes
(
file_node_id TEXT PRIMARY KEY,
file_node_name text not null,
file_node_parent_node_id INTEGER not null
CONSTRAINT fk_node_node_id
REFERENCES nodes(node_id) ,
file_node_generic_blob_id INTEGER not null
CONSTRAINT fk_generic_blob_generic_blob_id
REFERENCES generic_blob(generic_blob_id) ,
file_node_created_at BIGINT not null,
file_node_created_by INTEGER not null,
constraint unique_file_node
unique (file_node_parent_node_id, file_node_name)
);

View File

@ -21,7 +21,9 @@ import (
"errors"
"fmt"
"io"
"mime/multipart"
"github.com/harness/gitness/registry/app/driver"
"github.com/harness/gitness/registry/app/manifest"
"github.com/distribution/reference"
@ -159,3 +161,16 @@ type OciBlobStore interface {
Path() string
}
// GenericBlobStore represent the entire suite of Generic blob related operations. Such an
// implementation can access, read, write, delete and serve blobs.
type GenericBlobStore interface {
// Create allocates a new blob writer to add a blob to this service. The
// returned handle can be written to and later resumed using an opaque
// identifier. With this approach, one can Close and Resume a BlobWriter
// multiple times until the BlobWriter is committed or cancelled.
Create(ctx context.Context) (driver.FileWriter, error)
Write(w driver.FileWriter, file multipart.File) (int, error)
}

View File

@ -485,3 +485,37 @@ type GCManifestTaskRepository interface {
Delete(ctx context.Context, b *types.GCManifestTask) error
DeleteManifest(ctx context.Context, registryID, id int64) (*digest.Digest, error)
}
type NodesRepository interface {
// Get a node specified by ID
Get(ctx context.Context, id int64) (*types.Node, error)
// Get a node specified by node Name and registry id
GetByNameAndRegistryId(
ctx context.Context, registryID int64,
name string,
) (*types.Node, error)
// Create a node
Create(ctx context.Context, node *types.Node) error
// delete a node
deleteById(ctx context.Context, id int64) (err error)
}
type FileNodeRepository interface {
// Get a file node specified by ID
Get(ctx context.Context, id int64) (*types.FileNode, error)
// Create a file node
Create(ctx context.Context, fn *types.FileNode) error
// delete a node
deleteById(ctx context.Context, id int64) (err error)
}
type GenericBlobRepository interface {
FindByID(ctx context.Context, id int64) (*types.GenericBlob, error)
FindBySha256AndRootParentID(
ctx context.Context, sha256 string,
rootParentID int64,
) (*types.GenericBlob, error)
Create(ctx context.Context, gb *types.GenericBlob) (*types.GenericBlob, error)
DeleteByID(ctx context.Context, id int64) error
}

View File

@ -0,0 +1,26 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import "time"
type FileNode struct {
ID string
Name string
ParentNodeID int64
GenericBlobID string
CreatedAt time.Time
CreatedBy int64
}

View File

@ -0,0 +1,29 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import "time"
type GenericBlob struct {
ID string
RootParentID int64
Sha1 string
Sha256 string
Sha512 string
MD5 string
Size int64
CreatedAt time.Time
CreatedBy int64
}

28
registry/types/node.go Normal file
View File

@ -0,0 +1,28 @@
// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package types
import "time"
type Node struct {
ID string
Name string
RegistryID int64
ParentNodeID int64
IsFile bool
CompleteNodePath string
CreatedAt time.Time
CreatedBy int64
}