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

* Merge commit
* [AH-628]: Updated schema
BT-10437
Arvind Choudhary 2024-12-30 11:09:06 +00:00 committed by Harness
parent de86d126a5
commit 15f4adcbe0
8 changed files with 174 additions and 0 deletions

View File

@ -0,0 +1,2 @@
DROP TABLE IF EXISTS nodes;
DROP TABLE IF EXISTS generic_blobs;

View File

@ -0,0 +1,38 @@
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS generic_blobs
(
generic_blob_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
generic_blob_root_parent_id INTEGER NOT NULL,
generic_blob_sha_1 BYTEA,
generic_blob_sha_256 BYTEA NOT NULL,
generic_blob_sha_512 BYTEA,
generic_blob_md5 BYTEA,
generic_blob_size INTEGER NOT NULL,
generic_blob_created_at BIGINT NOT NULL,
generic_blob_created_by INTEGER NOT NULL,
CONSTRAINT unique_generic_blobs_sha_parent
UNIQUE (generic_blob_sha_256, generic_blob_root_parent_id)
);
CREATE TABLE IF NOT EXISTS nodes
(
node_id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
node_name TEXT NOT NULL,
node_parent_id UUID REFERENCES nodes (node_id),
node_registry_id INTEGER NOT NULL REFERENCES registries (registry_id),
node_is_file BOOLEAN NOT NULL,
node_path TEXT NOT NULL,
node_generic_blob_id UUID REFERENCES generic_blobs (generic_blob_id),
node_created_at BIGINT NOT NULL,
node_created_by INTEGER NOT NULL,
CONSTRAINT unique_nodes
UNIQUE (node_name, node_parent_id)
);
CREATE INDEX IF NOT EXISTS idx_nodes_parent_name ON nodes (node_parent_id, node_name);
CREATE INDEX IF NOT EXISTS idx_nodes_registry ON nodes (node_registry_id);
CREATE INDEX IF NOT EXISTS idx_nodes_blob ON nodes (node_generic_blob_id);
CREATE INDEX IF NOT EXISTS idx_generic_blobs_sha256 ON generic_blobs (generic_blob_sha_256);

View File

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

View File

@ -0,0 +1,34 @@
create table if not exists generic_blobs
(
generic_blob_id TEXT PRIMARY KEY,
generic_blob_root_parent_id INTEGER NOT NULL,
generic_blob_sha_1 BLOB,
generic_blob_sha_256 BLOB,
generic_blob_sha_512 BLOB NOT NULL,
generic_blob_md5 BLOB,
generic_blob_size INTEGER NOT NULL,
generic_blob_created_at INTEGER NOT NULL,
generic_blob_created_by INTEGER NOT NULL,
CONSTRAINT unique_generic_blob_parent_id unique (generic_blob_sha_256, generic_blob_root_parent_id)
);
create table if not exists nodes
(
node_id TEXT PRIMARY KEY,
node_name TEXT NOT NULL,
node_parent_id INTEGER REFERENCES nodes (node_id),
node_registry_id INTEGER NOT NULL REFERENCES registries (registry_id),
node_is_file BOOLEAN NOT NULL,
node_path TEXT NOT NULL,
node_generic_blob_id TEXT REFERENCES generic_blobs (generic_blob_id),
node_created_at INTEGER NOT NULL,
node_created_by INTEGER NOT NULL,
constraint unique_nodes
unique (node_name, node_parent_id)
);
CREATE INDEX IF NOT EXISTS idx_nodes_parent_name ON nodes (node_parent_id, node_name);
CREATE INDEX IF NOT EXISTS idx_nodes_registry ON nodes (node_registry_id);
CREATE INDEX IF NOT EXISTS idx_nodes_blob ON nodes (node_generic_blob_id);
CREATE INDEX IF NOT EXISTS idx_generic_blobs_sha256 ON generic_blobs (generic_blob_sha_256);

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,27 @@ 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 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,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
}

29
registry/types/node.go Normal file
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 Node struct {
ID string
Name string
ParentNodeID string
RegistryID int64
IsFile bool
NodePath string
BlobID string
CreatedAt time.Time
CreatedBy int64
}