Skip to content

Commit eaa2a00

Browse files
committed
db: add actions schemas and queries
1 parent 3c200bb commit eaa2a00

File tree

7 files changed

+463
-1
lines changed

7 files changed

+463
-1
lines changed

db/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const (
2222
// daemon.
2323
//
2424
// NOTE: This MUST be updated when a new migration is added.
25-
LatestMigrationVersion = 4
25+
LatestMigrationVersion = 5
2626
)
2727

2828
// MigrationTarget is a functional option that can be passed to applyMigrations

db/sqlc/actions.sql.go

Lines changed: 303 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DROP INDEX IF NOT EXISTS actions_state_idx;
2+
DROP INDEX IF NOT EXISTS actions_feature_name_idx;
3+
DROP INDEX IF NOT EXISTS actions_attempted_at_idx;
4+
DROP TABLE IF EXISTS actions;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CREATE TABLE IF NOT EXISTS actions(
2+
-- The ID of the action.
3+
id INTEGER PRIMARY KEY,
4+
5+
-- The session ID of the session that this action is associated with.
6+
-- This may be null for actions that are not coupled to a session.
7+
session_id BIGINT REFERENCES sessions(id) ON DELETE CASCADE,
8+
9+
-- The account ID of the account that this action is associated with.
10+
-- This may be null for actions that are not coupled to an account.
11+
account_id BIGINT REFERENCES accounts(id) ON DELETE CASCADE,
12+
13+
-- An ID derived from the macaroon used to perform the action. NOTE that
14+
-- this is only set if both session_id and account_id are null.
15+
macaroon_identifier BLOB,
16+
17+
-- The name of the entity who performed the action.
18+
actor_name TEXT,
19+
20+
-- The name of the feature that the action is being performed by.
21+
feature_name TEXT,
22+
23+
-- Meta info detailing what caused this action to be executed.
24+
trigger TEXT,
25+
26+
-- Meta info detailing what the intended outcome of this action will be.
27+
intent TEXT,
28+
29+
-- Extra structured JSON data that an actor can send along with the
30+
-- action as json.
31+
structured_json_data TEXT,
32+
33+
-- The method URI that was called.
34+
rpc_method TEXT NOT NULL,
35+
36+
-- The method parameters of the request in JSON form.
37+
rpc_params_json BLOB,
38+
39+
-- The time at which this action was created.
40+
created_at TIMESTAMP NOT NULL,
41+
42+
-- The current state of the action.
43+
state SMALLINT NOT NULL,
44+
45+
-- Human-readable reason for why the action failed.
46+
-- It will only be set if state is ActionStateError (3).
47+
error_reason TEXT
48+
);
49+
50+
CREATE INDEX IF NOT EXISTS actions_state_idx ON actions(state);
51+
CREATE INDEX IF NOT EXISTS actions_feature_name_idx ON actions(feature_name);
52+
CREATE INDEX IF NOT EXISTS actions_created_at_idx ON actions(created_at);

db/sqlc/models.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)