Skip to content

Commit 0521bf6

Browse files
authored
chore(cloud_hub): Make Fly the source of truth for IDs (#385)
Instead of storing IDs in the DB, use the GraphQL API to retrieve them. Partially reverts #384.
1 parent 1d99708 commit 0521bf6

File tree

14 files changed

+244
-21868
lines changed

14 files changed

+244
-21868
lines changed

services/celest_cloud_hub/drift_schema/cloud_hub_database/drift_schema_v2.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

services/celest_cloud_hub/lib/src/context.dart

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import 'package:celest/src/config/config_values.dart';
22
import 'package:celest/src/core/context.dart' as core;
33
import 'package:celest_cloud_hub/src/deploy/fly/fly_api.dart';
4+
import 'package:celest_cloud_hub/src/deploy/fly/fly_ctl.dart';
5+
import 'package:celest_cloud_hub/src/deploy/fly/fly_gql.dart';
6+
import 'package:graphql/client.dart';
47

58
export 'package:celest/src/core/context.dart' show ContextKey;
69

@@ -23,4 +26,28 @@ extension type Context._(core.Context _ctx) implements core.Context {
2326
);
2427
return _ctx.put(_flyContextKey, flyApi);
2528
}
29+
30+
FlyGql get flyGql {
31+
const contextKey = core.ContextKey<FlyGql>('FlyGqlClient');
32+
if (_ctx.get(contextKey) case final flyGql?) {
33+
return flyGql;
34+
}
35+
final client = GraphQLClient(
36+
cache: GraphQLCache(store: InMemoryStore()),
37+
link: AuthLink(
38+
getToken: () => 'FlyV1 $flyAuthToken',
39+
).concat(HttpLink('https://api.fly.io/graphql')),
40+
);
41+
final flyGql = FlyGql(client);
42+
return _ctx.put(contextKey, flyGql);
43+
}
44+
45+
FlyCtl get flyCtl {
46+
const contextKey = core.ContextKey<FlyCtl>('FlyCtl');
47+
if (_ctx.get(contextKey) case final flyCtl?) {
48+
return flyCtl;
49+
}
50+
final flyCtl = FlyCtl(flyAuthToken: flyAuthToken);
51+
return _ctx.put(contextKey, flyCtl);
52+
}
2653
}

services/celest_cloud_hub/lib/src/database/cloud_hub_database.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class CloudHubDatabase extends $CloudHubDatabase
4545
}
4646

4747
@override
48-
int get schemaVersion => 2;
48+
int get schemaVersion => 1;
4949

5050
static final Entity rootOrg = Entity(
5151
uid: const EntityUid.of('Celest::Organization', 'celest-dev'),

services/celest_cloud_hub/lib/src/database/schema/project_environments.drift

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,14 @@ CREATE TABLE IF NOT EXISTS project_environment_states (
177177
-- The ID of the linked project environment.
178178
project_environment_id TEXT NOT NULL PRIMARY KEY,
179179

180-
-- The domain name of the project environment.
181-
domain_name TEXT,
182-
183180
-- The name of the project environment's Fly app.
184181
fly_app_name TEXT,
185182

186183
-- The name of the project environment's Fly volume.
187-
--
188-
-- Different Fly commands require the use of the name of the ID,
189-
-- thus we store both.
190184
fly_volume_name TEXT,
191185

192-
-- The ID of the project environment's Fly volume.
193-
--
194-
-- Different Fly commands require the use of the name of the ID,
195-
-- thus we store both.
196-
fly_volume_id TEXT,
186+
-- The domain name of the project environment.
187+
domain_name TEXT,
197188

198189
CONSTRAINT fk_project_environment_state_project_environment_id FOREIGN KEY (project_environment_id) REFERENCES project_environments(id)
199190
ON UPDATE CASCADE ON DELETE CASCADE
@@ -303,28 +294,24 @@ getProjectEnvironmentState:
303294

304295
upsertProjectEnvironmentState(
305296
:projectEnvironmentId AS TEXT,
306-
:domainName AS TEXT OR NULL,
307297
:flyAppName AS TEXT OR NULL,
308298
:flyVolumeName AS TEXT OR NULL,
309-
:flyVolumeId AS TEXT OR NULL
299+
:domainName AS TEXT OR NULL
310300
):
311301
INSERT INTO project_environment_states (
312302
project_environment_id,
313-
domain_name,
314303
fly_app_name,
315304
fly_volume_name,
316-
fly_volume_id
305+
domain_name
317306
) VALUES (
318307
:projectEnvironmentId,
319-
:domainName,
320308
:flyAppName,
321309
:flyVolumeName,
322-
:flyVolumeId
310+
:domainName
323311
)
324312
ON CONFLICT (project_environment_id) DO UPDATE
325313
SET
326-
domain_name = coalesce(:domainName, domain_name),
327314
fly_app_name = coalesce(:flyAppName, fly_app_name),
328315
fly_volume_name = coalesce(:flyVolumeName, fly_volume_name),
329-
fly_volume_id = coalesce(:flyVolumeId, fly_volume_id)
316+
domain_name = coalesce(:domainName, domain_name)
330317
RETURNING *;

0 commit comments

Comments
 (0)