chore: mercury changes

This commit is contained in:
xuu
2024-04-05 12:40:51 -06:00
parent d4e021386b
commit 1f8b4ab24f
19 changed files with 895 additions and 298 deletions

View File

@@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS mercury_spaces
id integer NOT NULL DEFAULT nextval('mercury_spaces_id_seq'::regclass),
notes character varying[] NOT NULL DEFAULT '{}'::character varying[],
tags character varying[] NOT NULL DEFAULT '{}'::character varying[],
trailer character varying[] NOT NULL DEFAULT '{}'::character varying[],
CONSTRAINT mercury_namespace_pk PRIMARY KEY (id)
);
CREATE UNIQUE INDEX IF NOT EXISTS mercury_namespace_space_uindex
@@ -35,7 +36,8 @@ CREATE OR REPLACE VIEW mercury_registry_vw
v.name,
v."values",
v.notes,
v.tags
v.tags,
s.trailer
FROM mercury_spaces s
JOIN mercury_values v ON s.id = v.id;

View File

@@ -3,7 +3,8 @@ CREATE TABLE IF NOT EXISTS mercury_spaces
space character varying NOT NULL unique,
id integer NOT NULL CONSTRAINT mercury_namespace_pk PRIMARY KEY autoincrement,
notes json NOT NULL DEFAULT '[]',
tags json NOT NULL DEFAULT '[]'
tags json NOT NULL DEFAULT '[]',
trailer json NOT NULL DEFAULT '[]'
);
CREATE TABLE IF NOT EXISTS mercury_values
@@ -27,7 +28,8 @@ CREATE VIEW if not exists mercury_registry_vw
v.name,
v."values",
v.notes,
v.tags
v.tags,
s.trailer
FROM mercury_spaces s
JOIN mercury_values v ON s.id = v.id;

View File

@@ -166,7 +166,7 @@ func (p *sqlHandler) listSpace(ctx context.Context, tx sq.BaseRunner, where sq.S
tx = p.db
}
query := sq.Select(`"id"`, `"space"`, `"tags"`, `"notes"`).
query := sq.Select(`"id"`, `"space"`, `"notes"`, `"tags"`, `"trailer"`).
From("mercury_spaces").
Where(where).
OrderBy("space asc").
@@ -189,6 +189,7 @@ func (p *sqlHandler) listSpace(ctx context.Context, tx sq.BaseRunner, where sq.S
&s.Space.Space,
listScan(&s.Space.Notes, p.listFormat),
listScan(&s.Space.Tags, p.listFormat),
listScan(&s.Trailer, p.listFormat),
)
if err != nil {
return nil, err
@@ -287,6 +288,7 @@ func (p *sqlHandler) WriteConfig(ctx context.Context, config mercury.Config) (er
Where(sq.Eq{"id": updateIDs[i]}).
Set("tags", listValue(u.Tags, p.listFormat)).
Set("notes", listValue(u.Notes, p.listFormat)).
Set("trailer", listValue(u.Trailer, p.listFormat)).
PlaceholderFormat(sq.Dollar)
span.AddEvent(lg.LogQuery(query.ToSql()))
_, err := query.RunWith(tx).ExecContext(ctx)
@@ -305,8 +307,13 @@ func (p *sqlHandler) WriteConfig(ctx context.Context, config mercury.Config) (er
var id uint64
query := sq.Insert("mercury_spaces").
PlaceholderFormat(sq.Dollar).
Columns("space", "tags", "notes").
Values(s.Space, listValue(s.Tags, p.listFormat), listValue(s.Notes, p.listFormat)).
Columns("space", "tags", "notes", "trailer").
Values(
s.Space,
listValue(s.Tags, p.listFormat),
listValue(s.Notes, p.listFormat),
listValue(s.Trailer, p.listFormat),
).
Suffix("RETURNING \"id\"")
span.AddEvent(lg.LogQuery(query.ToSql()))