Skip to content

Commit d414e69

Browse files
authored
refactor(server): unify policy persistence in objects table (#972)
* refactor(server): unify policy persistence in objects table Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com> * fix(server): clean sandbox-owned records on reconcile delete * refactor(server): use protos for stored policy records * refactor(server): move policy persistence into policy_store * fix(server): restore compute runtime merge compatibility * fix(server): validate draft chunk sandbox ownership --------- Signed-off-by: John Myers <9696606+johntmyers@users.noreply.github.com>
1 parent 3e69c36 commit d414e69

17 files changed

Lines changed: 1819 additions & 915 deletions
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
CREATE TABLE IF NOT EXISTS objects (
2-
object_type TEXT NOT NULL,
3-
id TEXT NOT NULL,
4-
name TEXT NOT NULL,
5-
payload BYTEA NOT NULL,
2+
id TEXT PRIMARY KEY,
3+
object_type TEXT NOT NULL,
4+
name TEXT,
5+
scope TEXT,
6+
version BIGINT,
7+
status TEXT,
8+
dedup_key TEXT,
9+
hit_count BIGINT NOT NULL DEFAULT 0,
10+
payload BYTEA NOT NULL,
611
created_at_ms BIGINT NOT NULL,
7-
updated_at_ms BIGINT NOT NULL,
8-
PRIMARY KEY (id),
9-
UNIQUE (object_type, name)
12+
updated_at_ms BIGINT NOT NULL
1013
);
14+
15+
CREATE UNIQUE INDEX IF NOT EXISTS objects_name_uq
16+
ON objects (object_type, name)
17+
WHERE name IS NOT NULL;
18+
19+
CREATE UNIQUE INDEX IF NOT EXISTS objects_version_uq
20+
ON objects (object_type, scope, version)
21+
WHERE scope IS NOT NULL AND version IS NOT NULL;
22+
23+
CREATE INDEX IF NOT EXISTS objects_scope_status_idx
24+
ON objects (object_type, scope, status, version)
25+
WHERE scope IS NOT NULL;
26+
27+
CREATE UNIQUE INDEX IF NOT EXISTS objects_dedup_uq
28+
ON objects (object_type, scope, dedup_key)
29+
WHERE dedup_key IS NOT NULL;

crates/openshell-server/migrations/postgres/002_create_sandbox_policies.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/openshell-server/migrations/postgres/003_create_policy_recommendations.sql

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
CREATE TABLE IF NOT EXISTS objects (
2-
object_type TEXT NOT NULL,
3-
id TEXT NOT NULL,
4-
name TEXT NOT NULL,
5-
payload BLOB NOT NULL,
2+
id TEXT PRIMARY KEY,
3+
object_type TEXT NOT NULL,
4+
name TEXT,
5+
scope TEXT,
6+
version INTEGER,
7+
status TEXT,
8+
dedup_key TEXT,
9+
hit_count INTEGER NOT NULL DEFAULT 0,
10+
payload BLOB NOT NULL,
611
created_at_ms INTEGER NOT NULL,
7-
updated_at_ms INTEGER NOT NULL,
8-
PRIMARY KEY (id),
9-
UNIQUE (object_type, name)
12+
updated_at_ms INTEGER NOT NULL
1013
);
14+
15+
CREATE UNIQUE INDEX IF NOT EXISTS objects_name_uq
16+
ON objects (object_type, name)
17+
WHERE name IS NOT NULL;
18+
19+
CREATE UNIQUE INDEX IF NOT EXISTS objects_version_uq
20+
ON objects (object_type, scope, version)
21+
WHERE scope IS NOT NULL AND version IS NOT NULL;
22+
23+
CREATE INDEX IF NOT EXISTS objects_scope_status_idx
24+
ON objects (object_type, scope, status, version)
25+
WHERE scope IS NOT NULL;
26+
27+
CREATE UNIQUE INDEX IF NOT EXISTS objects_dedup_uq
28+
ON objects (object_type, scope, dedup_key)
29+
WHERE dedup_key IS NOT NULL;

crates/openshell-server/migrations/sqlite/002_create_sandbox_policies.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

crates/openshell-server/migrations/sqlite/003_create_policy_recommendations.sql

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)