|
| 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 |
0 commit comments