From 0a6a6bb66d26b29237076c799799a0d1ccd80b17 Mon Sep 17 00:00:00 2001 From: saji Date: Wed, 6 Mar 2024 15:15:56 -0600 Subject: [PATCH] add openmct domain object table and skeleton --- db.go | 36 ++++++------------------------ migrations/7_domainobject_down.sql | 2 ++ migrations/7_domainobject_up.sql | 6 +++++ 3 files changed, 15 insertions(+), 29 deletions(-) create mode 100644 migrations/7_domainobject_down.sql create mode 100644 migrations/7_domainobject_up.sql diff --git a/db.go b/db.go index a467f74..659e733 100644 --- a/db.go +++ b/db.go @@ -314,40 +314,18 @@ func (tdb *TelemDb) GetValues(ctx context.Context, filter BusEventFilter, return data, nil } -// PacketDef is a database packet model -type PacketDef struct { - Name string - Description string - Id int +func (tdb *TelemDb) AddDocument(obj json.RawMessage) error { + return nil } -type FieldDef struct { - Name string - SubName string - Packet string - Type string +func (tdb *TelemDb) UpdateDocument(key string, obj json.RawMessage) error { + return nil } -// PacketNotFoundError is when a matching packet cannot be found. -type PacketNotFoundError string - -func (e *PacketNotFoundError) Error() string { - return "packet not found: " + string(*e) -} - -// GetPacketDefN retrieves a packet matching the given name, if it exists. -// returns PacketNotFoundError if a matching packet could not be found. -func (tdb *TelemDb) GetPacketDefN(name string) (*PacketDef, error) { +func (tdb *TelemDb) GetDocument(key string) (json.RawMessage, error) { return nil, nil } -// GetPacketDefF retrieves the parent packet for a given field. -// This function cannot return PacketNotFoundError since we have SQL FKs enforcing. -func (tdb *TelemDb) GetPacketDefF(field FieldDef) (*PacketDef, error) { - return nil, nil -} - -// GetFieldDefs returns the given fields for a given packet definition. -func (tdb *TelemDb) GetFieldDefs(pkt PacketDef) ([]FieldDef, error) { - return nil, nil +func (tdb *TelemDb) DeleteDocument(key string) error { + return nil } diff --git a/migrations/7_domainobject_down.sql b/migrations/7_domainobject_down.sql new file mode 100644 index 0000000..ea1b8e5 --- /dev/null +++ b/migrations/7_domainobject_down.sql @@ -0,0 +1,2 @@ +DROP TABLE openmct_objects; +DROP INDEX openmct_key; diff --git a/migrations/7_domainobject_up.sql b/migrations/7_domainobject_up.sql new file mode 100644 index 0000000..90f9f1e --- /dev/null +++ b/migrations/7_domainobject_up.sql @@ -0,0 +1,6 @@ +CREATE TABLE openmct_objects ( + data TEXT, + key TEXT GENERATED ALWAYS AS (json_extract(data, '$.identifier.key')) VIRTUAL UNIQUE NOT NULL +); +-- fast key-lookup +CREATE INDEX openmct_key on openmct_objects(key);