changed metadata table to facts table, for semantical correctness

This commit is contained in:
d1nch8g
2026-04-15 09:36:22 +03:00
parent 3bda748b36
commit ca80a9219e
4 changed files with 17 additions and 20 deletions
+2
View File
@@ -27,4 +27,6 @@ test:
go test -timeout=30s -count=1 -cover ./...
clean:
docker compose down
sudo rm -rf /tmp/pg
docker compose up
+8 -11
View File
@@ -28,12 +28,10 @@ type Chat struct {
Identifier string // @username, email, phone
}
// Metadata stores facts Jules knows about a user.
type Metadata struct {
ID uuid.UUID
UserID uuid.UUID
CreatedAt time.Time
Value string
// Fact stores fact Jules knows about a user.
type Fact struct {
UserID uuid.UUID
Value string
}
// Contact represents a relationship between two Jules users.
@@ -77,12 +75,11 @@ type Chats interface {
Detach(ctx context.Context, userID uuid.UUID, platform string) error
}
// MetadataStore manages metadata persistence.
type MetadataStore interface {
// Facts manages facts persistence.
type Facts interface {
Add(ctx context.Context, userID uuid.UUID, value string) error
List(ctx context.Context, userID uuid.UUID) ([]Metadata, error)
Delete(ctx context.Context, id uuid.UUID) error
DeleteOlderThan(ctx context.Context, userID uuid.UUID, t time.Time) error
List(ctx context.Context, userID uuid.UUID) ([]Fact, error)
Delete(ctx context.Context, userID uuid.UUID, value string) error
}
// Contacts manages contact persistence.
@@ -12,15 +12,13 @@ CREATE TABLE chats (
PRIMARY KEY (user_id, platform)
);
CREATE TABLE metadata (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
value TEXT NOT NULL
CREATE TABLE facts (
user_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
value TEXT NOT NULL,
PRIMARY KEY (user_id, value)
);
CREATE INDEX idx_metadata_user_id ON metadata(user_id);
CREATE INDEX idx_metadata_created_at ON metadata(created_at);
CREATE INDEX idx_facts_user_id ON facts(user_id);
CREATE TABLE contacts (
owner_id UUID NOT NULL REFERENCES users(id) ON DELETE CASCADE,
+2 -2
View File
@@ -36,14 +36,14 @@ func getTestConn(t *testing.T) *sql.DB {
}
func cleanTables(_ *testing.T, conn *sql.DB) {
tables := []string{"actions", "notifications", "contacts", "metadata", "chats", "users"}
tables := []string{"actions", "notifications", "contacts", "facts", "chats", "users"}
for _, table := range tables {
_, _ = conn.ExecContext(context.Background(), "TRUNCATE TABLE "+table+" CASCADE")
}
}
func dropSchema(_ *testing.T, conn *sql.DB) {
tables := []string{"actions", "notifications", "contacts", "metadata", "chats", "users"}
tables := []string{"actions", "notifications", "contacts", "facts", "chats", "users"}
for _, table := range tables {
_, _ = conn.ExecContext(context.Background(), "DROP TABLE IF EXISTS "+table+" CASCADE")
}