Skip to content

Commit

Permalink
Object store metadata schema
Browse files Browse the repository at this point in the history
The object store will require tracking the underlying blobs of the
object store. To do this we need to keep track of the path, size
and hash. The path needs to be unique so multiple files are not
added, the hash is not unqiue as multiple metadata can point to
the same blob.
  • Loading branch information
SimonRichardson committed Nov 10, 2023
1 parent 39cb3f1 commit ab33404
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions domain/schema/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func ControllerDDL() *schema.Schema {
changeLogTriggersForTable("upgrade_info", "uuid", tableUpgradeInfo),
changeLogTriggersForTable("upgrade_info_controller_node", "upgrade_info_uuid", tableUpgradeInfoControllerNode),
autocertCacheSchema,
objectStoreMetadataSchema,
}

schema := schema.New()
Expand Down
1 change: 1 addition & 0 deletions domain/schema/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func ModelDDL() *schema.Schema {
modelConfig,
changeLogTriggersForTable("model_config", "key", tableModelConfig),
spacesSchema,
objectStoreMetadataSchema,
}

schema := schema.New()
Expand Down
48 changes: 48 additions & 0 deletions domain/schema/objectstore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2023 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package schema

import "github.com/juju/juju/core/database/schema"

// objectStoreMetadataSchema provides a helper function for generating a change_log ddl
// for a schema.
func objectStoreMetadataSchema() schema.Patch {
return schema.MakePatch(`
CREATE TABLE object_store_metadata_hash_type (
id INT PRIMARY KEY,
hash_type TEXT NOT NULL
);
CREATE UNIQUE INDEX idx_object_store_metadata_hash_type_name
ON object_store_metadata_hash_type (hash_type);
INSERT INTO object_store_metadata_hash_type VALUES
(0, 'none'),
(1, 'sha-256');
CREATE TABLE object_store_metadata (
uuid TEXT PRIMARY KEY,
hash_type_id INT NOT NULL,
hash TEXT,
CONSTRAINT fk_object_store_metadata_hash_type
FOREIGN KEY (hash_type_id)
REFERENCES object_store_metadata_hash_type(id)
);
CREATE UNIQUE INDEX idx_object_store_metadata_hash ON object_store_metadata (hash);
CREATE TABLE object_store_metadata_path (
uuid TEXT PRIMARY KEY,
metadata_uuid TEXT NOT NULL,
path TEXT NOT NULL,
size INT NOT NULL,
CONSTRAINT fk_object_store_metadata_metadata_uuid
FOREIGN KEY (metadata_uuid)
REFERENCES object_store_metadata(uuid)
);
CREATE UNIQUE INDEX idx_object_store_metadata_path ON object_store_metadata_path (path);
`)
}
10 changes: 10 additions & 0 deletions domain/schema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func (s *schemaSuite) TestControllerDDLApply(c *gc.C) {
"upgrade_info",
"upgrade_info_controller_node",
"upgrade_state_type",

// Object store metadata
"object_store_metadata",
"object_store_metadata_path",
"object_store_metadata_hash_type",
)
c.Assert(readTableNames(c, s.DB()), jc.SameContents, expected.Union(internalTableNames).SortedValues())
}
Expand All @@ -112,6 +117,11 @@ func (s *schemaSuite) TestModelDDLApply(c *gc.C) {
// Spaces
"spaces",
"provider_spaces",

// Object store metadata
"object_store_metadata",
"object_store_metadata_path",
"object_store_metadata_hash_type",
)
c.Assert(readTableNames(c, s.DB()), jc.SameContents, expected.Union(internalTableNames).SortedValues())
}
Expand Down

0 comments on commit ab33404

Please sign in to comment.