-
Notifications
You must be signed in to change notification settings - Fork 924
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(agents-api): Add cozo migrations for tasks schema (#349)
Signed-off-by: Diwank Tomer <[email protected]> Co-authored-by: Diwank Tomer <[email protected]>
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
agents-api/migrations/migrate_1716939839_task_relations.py
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,80 @@ | ||
# /usr/bin/env python3 | ||
|
||
MIGRATION_ID = "task_relations" | ||
CREATED_AT = 1716939839.690704 | ||
|
||
|
||
def run(client, queries): | ||
joiner = "}\n\n{" | ||
|
||
query = joiner.join(queries) | ||
query = f"{{\n{query}\n}}" | ||
client.run(query) | ||
|
||
|
||
create_task_relation_query = dict( | ||
up=""" | ||
:create tasks { | ||
agent_id: Uuid, | ||
task_id: Uuid, | ||
updated_at_ms: Validity default [floor(now() * 1000), true], | ||
=> | ||
name: String, | ||
description: String? default null, | ||
input_schema: Json, | ||
tools_available: [Uuid] default [], | ||
workflows: [Json], | ||
created_at: Float default now(), | ||
} | ||
""", | ||
down="::remove tasks", | ||
) | ||
|
||
create_execution_relation_query = dict( | ||
up=""" | ||
:create executions { | ||
task_id: Uuid, | ||
execution_id: Uuid, | ||
=> | ||
status: String default 'queued', | ||
# one of: "queued", "starting", "running", "waiting-for-input", "success", "failed" | ||
arguments: Json, | ||
created_at: Float default now(), | ||
updated_at: Float default now(), | ||
} | ||
""", | ||
down="::remove executions", | ||
) | ||
|
||
create_transition_relation_query = dict( | ||
up=""" | ||
:create transitions { | ||
execution_id: Uuid, | ||
transition_id: Uuid, | ||
=> | ||
type: String, | ||
# one of: "finished", "waiting", "error", "step" | ||
from: (String, Int), | ||
to: (String, Int)?, | ||
output: Json, | ||
created_at: Float default now(), | ||
} | ||
""", | ||
down="::remove transitions", | ||
) | ||
|
||
queries = [ | ||
create_task_relation_query, | ||
create_execution_relation_query, | ||
create_transition_relation_query, | ||
] | ||
|
||
|
||
def up(client): | ||
run(client, [q["up"] for q in queries]) | ||
|
||
|
||
def down(client): | ||
run(client, [q["down"] for q in reversed(queries)]) |