Skip to content

Commit 07a8f10

Browse files
mig: add flyio reap tracking (#824)
This migrations updates the fly_apps table to help identify apps to reap and track an any errors encountered during the reaping process.
1 parent a799d09 commit 07a8f10

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

server/database/schema.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ CREATE TABLE IF NOT EXISTS fly_apps (
430430
status TEXT NOT NULL, -- pending, ready, failed
431431

432432
reaped_at timestamptz, -- when we deleted an app and its resources on fly.io
433+
reap_error TEXT, -- error message if reaping failed
433434

434435
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
435436
updated_at timestamptz NOT NULL DEFAULT clock_timestamp(),
@@ -441,7 +442,8 @@ CREATE TABLE IF NOT EXISTS fly_apps (
441442
CONSTRAINT fly_apps_access_id_fkey FOREIGN KEY (access_id) REFERENCES functions_access (id) ON DELETE CASCADE
442443
);
443444

444-
CREATE UNIQUE INDEX IF NOT EXISTS fly_apps_project_deployment_function_key ON fly_apps (project_id, deployment_id, function_id, status);
445+
CREATE UNIQUE INDEX IF NOT EXISTS fly_apps_project_deployment_function_active_key ON fly_apps (project_id, deployment_id, function_id) WHERE reaped_at IS NULL;
446+
CREATE INDEX IF NOT EXISTS fly_apps_reaper_idx ON fly_apps (project_id, created_at DESC) WHERE status = 'ready' AND reaped_at IS NULL;
445447
CREATE UNIQUE INDEX IF NOT EXISTS fly_apps_seq_key ON fly_apps (seq DESC);
446448
CREATE INDEX IF NOT EXISTS fly_apps_access_id_idx ON fly_apps (access_id DESC);
447449

server/internal/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- atlas:txmode none
2+
3+
-- Drop index "fly_apps_project_deployment_function_key" from table: "fly_apps"
4+
DROP INDEX CONCURRENTLY "fly_apps_project_deployment_function_key";
5+
-- Modify "fly_apps" table
6+
ALTER TABLE "fly_apps" ADD COLUMN "reap_error" text NULL;
7+
-- Create index "fly_apps_project_deployment_function_active_key" to table: "fly_apps"
8+
CREATE UNIQUE INDEX CONCURRENTLY "fly_apps_project_deployment_function_active_key" ON "fly_apps" ("project_id", "deployment_id", "function_id") WHERE (reaped_at IS NULL);
9+
-- Create index "fly_apps_reaper_idx" to table: "fly_apps"
10+
CREATE INDEX CONCURRENTLY "fly_apps_reaper_idx" ON "fly_apps" ("project_id", "created_at" DESC) WHERE ((status = 'ready'::text) AND (reaped_at IS NULL));

server/migrations/atlas.sum

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
h1:wogdDQltJwCokZjsdCSpOhzcsGWHVCLvKNJJNhRKxuE=
1+
h1:Qm7TluoIHDgRPjohVd9rnZiUJZci3BU+Kp9X/ZLqV1s=
22
20250502122425_initial-tables.sql h1:Hu3O60/bB4fjZpUay8FzyOjw6vngp087zU+U/wVKn7k=
33
20250502130852_initial-indexes.sql h1:oYbnwi9y9PPTqu7uVbSPSALhCY8XF3rv03nDfG4b7mo=
44
20250502154250_relax-http-security-fields.sql h1:0+OYIDq7IHmx7CP5BChVwfpF2rOSrRDxnqawXio2EVo=
@@ -66,3 +66,4 @@ h1:wogdDQltJwCokZjsdCSpOhzcsGWHVCLvKNJJNhRKxuE=
6666
20251105184547_add-organization-features-table.sql h1:1OTlrIlL1jagd9BRvB1hO3B7c+1XRMvHhw1GSGKPPWA=
6767
20251110195659_add-pgvector-extension.sql h1:JWfchfuTbSewGzYrDlymV5RiwYvaFcC2tvKBjdulhNI=
6868
20251111165847_add-toolset-embedding-migration.sql h1:1cuNc8gF7U8EKK7agVmvP3FdS6+U36oSwVc8G6yyzHg=
69+
20251111180235_fly-apps-reap-state.sql h1:7ml5z97oDOZwEf26Lc57uA/SA7Q7dOktOmaxv1IZ9Ck=

0 commit comments

Comments
 (0)