Files
Containr/app/backend/migrations_goose/20260921000000_scaling_policies.sql
T
Tomas DvorakandDevin 25e4f676a9 feat: persist scaling policies to Postgres
Adds scaling_policies table and wires the autoscaler: upsert on every
SetScalingPolicy (including delete-as-disable), LoadPolicies hydrates
policies + service states at boot. Persist failures are logged, never
fatal — in-memory state stays authoritative.

Verified live: policy written on POST, survives a full backend restart,
service state re-registers at min_replicas. Also gofmt-fixes the
drifted databases.go struct tags.

Authored By: TDvorak <[email protected]>

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-17 18:44:06 +02:00

21 lines
840 B
SQL

-- +goose Up
CREATE TABLE IF NOT EXISTS scaling_policies (
service_id uuid PRIMARY KEY REFERENCES services(id) ON DELETE CASCADE,
min_replicas integer NOT NULL DEFAULT 1,
max_replicas integer NOT NULL DEFAULT 1,
target_cpu double precision NOT NULL DEFAULT 0,
target_memory double precision NOT NULL DEFAULT 0,
scale_up_cooldown bigint NOT NULL DEFAULT 0,
scale_down_cooldown bigint NOT NULL DEFAULT 0,
scale_up_step integer NOT NULL DEFAULT 1,
scale_down_step integer NOT NULL DEFAULT 1,
metrics jsonb,
thresholds jsonb,
enabled boolean NOT NULL DEFAULT true,
cost_optimization jsonb,
updated_at timestamptz NOT NULL DEFAULT now()
);
-- +goose Down
DROP TABLE IF EXISTS scaling_policies;