Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion marketplace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ go_library(
"//private/trust:go_default_library",
"@com_connectrpc_connect//:go_default_library",
"@com_github_golang_jwt_jwt//:go_default_library",
"@org_golang_google_protobuf//types/known/timestamppb:go_default_library",
"@org_golang_x_crypto//bcrypt:go_default_library",
],
)
Expand Down
37 changes: 23 additions & 14 deletions marketplace/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,33 @@ CREATE TABLE IF NOT EXISTS Assets(
account_id INTEGER,
isd_id INTEGER NOT NULL,
as_id INTEGER NOT NULL,
bandwidth INTEGER NOT NULL,
bandwidth INTEGER NOT NULL CHECK (bandwidth > 0),
bandwidth_min INTEGER NOT NULL,
bandwidth_max INTEGER NOT NULL CHECK (bandwidth_max >= bandwidth_min),
price INTEGER NOT NULL,
time_granularity INTEGER NOT NULL,
time_min_duration INTEGER NOT NULL,
time_max_duration INTEGER NOT NULL,
starts_at TEXT NOT NULL,
stops_at TEXT NOT NULL,
starts_at INTEGER NOT NULL,
stops_at INTEGER NOT NULL,
ingress INTEGER,
egress INTEGER,
state INTEGER NOT NULL DEFAULT 0,
FOREIGN KEY (account_id) REFERENCES Accounts(id)
);
CREATE INDEX IF NOT EXISTS idx_asset_owner ON Assets(account_id);
CREATE INDEX IF NOT EXISTS idx_asset_validity ON Assets(starts_at, stops_at);
CREATE INDEX IF NOT EXISTS idx_assets_ia_validity_start ON Assets(isd_id, as_id, starts_at, stops_at);
CREATE INDEX IF NOT EXISTS idx_assets_ia_validity_end ON Assets(isd_id, as_id, stops_at, starts_at);
CREATE INDEX IF NOT EXISTS idx_asset_owner ON Assets(account_id, isd_id, as_id);
CREATE INDEX IF NOT EXISTS idx_assets_validity ON Assets(isd_id, as_id, stops_at);

CREATE TABLE IF NOT EXISTS Asset_Segment(
asset_id INTEGER NOT NULL,
starts_at INTEGER NOT NULL,
stops_at INTEGER NOT NULL,
available INTEGER NOT NULL CHECK (available >= 0),
PRIMARY KEY (asset_id, starts_at),
CHECK (starts_at < stops_at),
FOREIGN KEY(asset_id) REFERENCES Assets(id) ON DELETE CASCADE
) WITHOUT ROWID;

CREATE TABLE IF NOT EXISTS Reservations(
id INTEGER PRIMARY KEY AUTOINCREMENT,
reservation_id INTEGER NOT NULL,
Expand All @@ -31,8 +40,8 @@ CREATE TABLE IF NOT EXISTS Reservations(
egress INTEGER NOT NULL,
bandwidth INTEGER NOT NULL,
bw_encoded INTEGER NOT NULL,
starts_at TEXT NOT NULL,
stops_at TEXT NOT NULL,
starts_at INTEGER NOT NULL,
stops_at INTEGER NOT NULL,
key BLOB NOT NULL,
FOREIGN KEY (account_id) REFERENCES Accounts(id)
);
Expand Down Expand Up @@ -70,8 +79,8 @@ CREATE TABLE IF NOT EXISTS Redemption_Delegations(
as_id INTEGER NOT NULL,
res_id_limit_low INTEGER NOT NULL DEFAULT 0,
res_id_limit_high INTEGER NOT NULL,
expiration TEXT NOT NULL CHECK (expiration <= paid_until),
paid_until TEXT NOT NULL,
expiration INTEGER NOT NULL CHECK (expiration <= paid_until),
paid_until INTEGER NOT NULL,
key BLOB NOT NULL,
encodings BLOB NOT NULL,
PRIMARY KEY(isd_id, as_id)
Expand All @@ -83,10 +92,10 @@ CREATE TABLE IF NOT EXISTS Asset_Events(
ingress INTEGER,
egress INTEGER,
bandwidth INTEGER NOT NULL,
starts_at TEXT NOT NULL,
stops_at TEXT NOT NULL,
starts_at INTEGER NOT NULL,
stops_at INTEGER NOT NULL,
price INTEGER NOT NULL,
event_type INTEGER NOT NULL,
event_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
event_at INTEGER NOT NULL DEFAULT (unixepoch())
);
CREATE INDEX IF NOT EXISTS idx_asset_events ON Asset_Events(event_type, isd_id, as_id, stops_at, starts_at);
Loading
Loading