Skip to content

Commit f34cd1f

Browse files
nalekseev-e2be2b-bot[bot]
authored andcommitted
feat(db): add team delete RPS fields
GitOrigin-RevId: b58e7fd40d714529d47c540997ae33d6d63f91c8
1 parent 25b1961 commit f34cd1f

86 files changed

Lines changed: 322 additions & 91 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎packages/auth/pkg/types/limits.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ type TeamLimits struct {
1414
DefaultFreeDiskSizeMb int64
1515
MaxFreeDiskSizeMb int64
1616

17-
APITeamRPSList int64
17+
APITeamRPSList int64
18+
APITeamRPSDelete int64
1819
}

‎packages/auth/pkg/types/teams.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func newTeamLimits(
2626
DiskMb: teamLimits.DiskMb,
2727
EventsTTLDays: teamLimits.EventsTtlDays,
2828
APITeamRPSList: teamLimits.ApiTeamRpsList,
29+
APITeamRPSDelete: teamLimits.ApiTeamRpsDelete,
2930

3031
DefaultFreeDiskSizeMb: teamLimits.DefaultFreeDiskSizeMb,
3132
MaxFreeDiskSizeMb: teamLimits.MaxFreeDiskSizeMb,

‎packages/auth/pkg/types/teams_test.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
authqueries "github.com/e2b-dev/infra/packages/db/pkg/auth/queries"
99
)
1010

11-
func TestNewTeamPreservesAPIListRate(t *testing.T) {
11+
func TestNewTeamPreservesAPIRates(t *testing.T) {
1212
t.Parallel()
1313

14-
team := NewTeam(&authqueries.Team{}, &authqueries.TeamLimit{ApiTeamRpsList: 1 << 32})
14+
team := NewTeam(&authqueries.Team{}, &authqueries.TeamLimit{ApiTeamRpsList: 1 << 32, ApiTeamRpsDelete: 1<<32 + 1})
1515
assert.Equal(t, int64(1<<32), team.Limits.APITeamRPSList)
16+
assert.Equal(t, int64(1<<32+1), team.Limits.APITeamRPSDelete)
1617
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE public.tiers
4+
ADD COLUMN api_team_rps_delete bigint NOT NULL DEFAULT 0
5+
CHECK (api_team_rps_delete >= 0);
6+
7+
ALTER TABLE public.addons
8+
ADD COLUMN extra_api_team_rps_delete bigint NOT NULL DEFAULT 0
9+
CHECK (extra_api_team_rps_delete >= 0);
10+
11+
CREATE OR REPLACE VIEW public.team_limits
12+
WITH (security_invoker=on) AS
13+
SELECT
14+
t.id,
15+
COALESCE(pl.max_length_hours, tier.max_length_hours) AS max_length_hours,
16+
COALESCE(pl.concurrent_sandboxes, tier.concurrent_instances + a.extra_concurrent_sandboxes) AS concurrent_sandboxes,
17+
COALESCE(pl.concurrent_template_builds, tier.concurrent_template_builds + a.extra_concurrent_template_builds) AS concurrent_template_builds,
18+
COALESCE(pl.max_vcpu, tier.max_vcpu + a.extra_max_vcpu) AS max_vcpu,
19+
COALESCE(pl.max_ram_mb, tier.max_ram_mb + a.extra_max_ram_mb) AS max_ram_mb,
20+
COALESCE(pl.disk_mb, tier.disk_mb + a.extra_disk_mb) AS disk_mb,
21+
COALESCE(pl.events_ttl_days, tier.events_ttl_days + a.extra_events_ttl_days) AS events_ttl_days,
22+
COALESCE(pl.default_free_disk_size_mb, (tier.default_free_disk_size_mb + a.extra_disk_mb))::bigint AS default_free_disk_size_mb,
23+
COALESCE(pl.max_disk_size_mb, (tier.max_disk_size_mb + a.extra_max_disk_size_mb))::bigint AS max_disk_size_mb,
24+
COALESCE(pl.max_disk_size_mb, (tier.max_disk_size_mb + a.extra_max_disk_size_mb))::bigint AS max_free_disk_size_mb,
25+
COALESCE(pl.api_team_rps_list, tier.api_team_rps_list + a.extra_api_team_rps_list)::bigint AS api_team_rps_list,
26+
(tier.api_team_rps_delete + a.extra_api_team_rps_delete)::bigint AS api_team_rps_delete
27+
FROM public.teams t
28+
JOIN public.tiers tier ON t.tier = tier.id
29+
LEFT JOIN public.project_limits pl ON pl.team_id = t.id
30+
LEFT JOIN LATERAL (
31+
SELECT COALESCE(SUM(extra_concurrent_sandboxes), 0)::bigint AS extra_concurrent_sandboxes,
32+
COALESCE(SUM(extra_concurrent_template_builds), 0)::bigint AS extra_concurrent_template_builds,
33+
COALESCE(SUM(extra_max_vcpu), 0)::bigint AS extra_max_vcpu,
34+
COALESCE(SUM(extra_max_ram_mb), 0)::bigint AS extra_max_ram_mb,
35+
COALESCE(SUM(extra_disk_mb), 0)::bigint AS extra_disk_mb,
36+
COALESCE(SUM(extra_events_ttl_days), 0)::bigint AS extra_events_ttl_days,
37+
COALESCE(SUM(COALESCE(extra_max_disk_size_mb, extra_disk_mb)), 0)::bigint AS extra_max_disk_size_mb,
38+
COALESCE(SUM(extra_api_team_rps_list), 0)::bigint AS extra_api_team_rps_list,
39+
COALESCE(SUM(extra_api_team_rps_delete), 0)::bigint AS extra_api_team_rps_delete
40+
FROM public.addons addon
41+
WHERE addon.team_id = t.id
42+
AND addon.valid_from <= now()
43+
AND (addon.valid_to IS NULL OR addon.valid_to > now())
44+
) a ON true;
45+
-- +goose StatementEnd
46+
47+
-- +goose Down
48+
-- +goose StatementBegin
49+
DROP VIEW public.team_limits;
50+
51+
CREATE VIEW public.team_limits
52+
WITH (security_invoker=on) AS
53+
SELECT
54+
t.id,
55+
COALESCE(pl.max_length_hours, tier.max_length_hours) AS max_length_hours,
56+
COALESCE(pl.concurrent_sandboxes, tier.concurrent_instances + a.extra_concurrent_sandboxes) AS concurrent_sandboxes,
57+
COALESCE(pl.concurrent_template_builds, tier.concurrent_template_builds + a.extra_concurrent_template_builds) AS concurrent_template_builds,
58+
COALESCE(pl.max_vcpu, tier.max_vcpu + a.extra_max_vcpu) AS max_vcpu,
59+
COALESCE(pl.max_ram_mb, tier.max_ram_mb + a.extra_max_ram_mb) AS max_ram_mb,
60+
COALESCE(pl.disk_mb, tier.disk_mb + a.extra_disk_mb) AS disk_mb,
61+
COALESCE(pl.events_ttl_days, tier.events_ttl_days + a.extra_events_ttl_days) AS events_ttl_days,
62+
COALESCE(pl.default_free_disk_size_mb, (tier.default_free_disk_size_mb + a.extra_disk_mb))::bigint AS default_free_disk_size_mb,
63+
COALESCE(pl.max_disk_size_mb, (tier.max_disk_size_mb + a.extra_max_disk_size_mb))::bigint AS max_disk_size_mb,
64+
COALESCE(pl.max_disk_size_mb, (tier.max_disk_size_mb + a.extra_max_disk_size_mb))::bigint AS max_free_disk_size_mb,
65+
COALESCE(pl.api_team_rps_list, tier.api_team_rps_list + a.extra_api_team_rps_list)::bigint AS api_team_rps_list
66+
FROM public.teams t
67+
JOIN public.tiers tier ON t.tier = tier.id
68+
LEFT JOIN public.project_limits pl ON pl.team_id = t.id
69+
LEFT JOIN LATERAL (
70+
SELECT COALESCE(SUM(extra_concurrent_sandboxes), 0)::bigint AS extra_concurrent_sandboxes,
71+
COALESCE(SUM(extra_concurrent_template_builds), 0)::bigint AS extra_concurrent_template_builds,
72+
COALESCE(SUM(extra_max_vcpu), 0)::bigint AS extra_max_vcpu,
73+
COALESCE(SUM(extra_max_ram_mb), 0)::bigint AS extra_max_ram_mb,
74+
COALESCE(SUM(extra_disk_mb), 0)::bigint AS extra_disk_mb,
75+
COALESCE(SUM(extra_events_ttl_days), 0)::bigint AS extra_events_ttl_days,
76+
COALESCE(SUM(COALESCE(extra_max_disk_size_mb, extra_disk_mb)), 0)::bigint AS extra_max_disk_size_mb,
77+
COALESCE(SUM(extra_api_team_rps_list), 0)::bigint AS extra_api_team_rps_list
78+
FROM public.addons addon
79+
WHERE addon.team_id = t.id
80+
AND addon.valid_from <= now()
81+
AND (addon.valid_to IS NULL OR addon.valid_to > now())
82+
) a ON true;
83+
84+
ALTER TABLE public.addons DROP COLUMN extra_api_team_rps_delete;
85+
ALTER TABLE public.tiers DROP COLUMN api_team_rps_delete;
86+
-- +goose StatementEnd

‎packages/db/pkg/auth/queries/create_team_api_key.sql.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/db/pkg/auth/queries/db.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/db/pkg/auth/queries/delete_public_user.sql.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/db/pkg/auth/queries/delete_team_api_key.sql.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/db/pkg/auth/queries/get_api_keys.sql.go‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/db/pkg/auth/queries/get_team.sql.go‎

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

0 commit comments

Comments
 (0)