-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request juju#16571 from SimonRichardson/objectstore-metada…
…ta-schema juju#16571 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. This is done in two tables, the `object_store_metadata` and `object_store_metadata_resource`. The first holds the path and size, along with the foreign key to the blob reference. As there may be many blobs with the same hash, we have a one-to-many mapping. *Why this change is needed and what it does.* ## Checklist - [x] Code style: imports ordered, good names, simple structure, etc - [x] Comments saying why design decisions were made - [x] Go unit tests, with comments saying what you're testing ## QA steps ```sh $ juju bootstrap lxd test --build-agent ``` ## Links **Jira card:** JUJU-4899
- Loading branch information
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters