1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
CREATE TABLE IF NOT EXISTS agent_marketplace_listings (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
publisher_user_id uuid NOT NULL REFERENCES users(id) ON DELETE CASCADE,
slug text NOT NULL UNIQUE,
name text NOT NULL,
tagline text NOT NULL DEFAULT '',
description text NOT NULL DEFAULT '',
category text NOT NULL DEFAULT 'custom',
pricing_model text NOT NULL DEFAULT 'free',
price_cents integer NOT NULL DEFAULT 0,
agent_template jsonb NOT NULL DEFAULT '{}'::jsonb,
source_url text,
status text NOT NULL DEFAULT 'draft',
install_count integer NOT NULL DEFAULT 0,
rating_avg numeric(3, 2) NOT NULL DEFAULT 0,
rating_count integer NOT NULL DEFAULT 0,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS agent_marketplace_listings_category
ON agent_marketplace_listings (category, status);
CREATE INDEX IF NOT EXISTS agent_marketplace_listings_rating
ON agent_marketplace_listings (rating_avg DESC, rating_count DESC);
CREATE INDEX IF NOT EXISTS agent_marketplace_listings_installs
ON agent_marketplace_listings (install_count DESC);
CREATE INDEX IF NOT EXISTS agent_marketplace_listings_publisher
ON agent_marketplace_listings (publisher_user_id);
CREATE INDEX IF NOT EXISTS agent_marketplace_listings_status_created
ON agent_marketplace_listings (status, created_at DESC);
CREATE TABLE IF NOT EXISTS agent_marketplace_installs (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
listing_id uuid NOT NULL
REFERENCES agent_marketplace_listings(id) ON DELETE CASCADE,
repository_id uuid NOT NULL
REFERENCES repositories(id) ON DELETE CASCADE,
installed_by_user_id uuid NOT NULL
REFERENCES users(id) ON DELETE CASCADE,
agent_session_id uuid
REFERENCES agent_sessions(id) ON DELETE SET NULL,
status text NOT NULL DEFAULT 'active',
installed_at timestamptz NOT NULL DEFAULT now(),
last_invoked_at timestamptz,
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE UNIQUE INDEX IF NOT EXISTS agent_marketplace_installs_listing_repo
ON agent_marketplace_installs (listing_id, repository_id);
CREATE INDEX IF NOT EXISTS agent_marketplace_installs_repo
ON agent_marketplace_installs (repository_id, status);
CREATE INDEX IF NOT EXISTS agent_marketplace_installs_installer
ON agent_marketplace_installs (installed_by_user_id);
CREATE TABLE IF NOT EXISTS agent_marketplace_reviews (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
listing_id uuid NOT NULL
REFERENCES agent_marketplace_listings(id) ON DELETE CASCADE,
reviewer_user_id uuid NOT NULL
REFERENCES users(id) ON DELETE CASCADE,
rating integer NOT NULL,
body text NOT NULL DEFAULT '',
created_at timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS agent_marketplace_reviews_listing_created
ON agent_marketplace_reviews (listing_id, created_at DESC);
CREATE INDEX IF NOT EXISTS agent_marketplace_reviews_reviewer
ON agent_marketplace_reviews (reviewer_user_id);
|