Skip to content

Commit 322c48f

Browse files
committed
fix(cli): Rename database environment variables
Use `${DATABASE_NAME}_HOST` and `${DATABASE_NAME}_TOKEN` instead of a hardcoded value.
1 parent 76e914b commit 322c48f

File tree

5 files changed

+17
-11
lines changed

5 files changed

+17
-11
lines changed

apps/cli/fixtures/standalone/data/goldens/celest.json

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

apps/cli/fixtures/standalone/data/lib/src/generated/data.celest.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class CelestData {
2424
context,
2525
name: 'TaskDatabase',
2626
factory: TaskDatabase.new,
27-
hostnameVariable: const _$celest.env('CELEST_DATABASE_HOST'),
28-
tokenSecret: const _$celest.secret('CELEST_DATABASE_TOKEN'),
27+
hostnameVariable: const _$celest.env('TASK_DATABASE_HOST'),
28+
tokenSecret: const _$celest.secret('TASK_DATABASE_TOKEN'),
2929
),
3030
);
3131
}

apps/cli/lib/src/analyzer/celest_analyzer.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,8 @@ const project = Project(name: 'cache_warmup');
348348
'resolveDatabases',
349349
_resolveDatabases,
350350
);
351-
if (databases.isNotEmpty) {
352-
_project.databases.addAll({
353-
for (final database in databases) database.name: database,
354-
});
351+
for (final database in databases) {
352+
_project.databases[database.name] = database;
355353
}
356354

357355
if (migrateProject) {

apps/cli/lib/src/analyzer/resolver/project_resolver.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:celest_cli/src/types/type_checker.dart';
2121
import 'package:celest_cli/src/utils/analyzer.dart';
2222
import 'package:celest_cli/src/utils/error.dart';
2323
import 'package:celest_cli/src/utils/list.dart';
24+
import 'package:celest_cli/src/utils/recase.dart';
2425
import 'package:celest_cli/src/utils/reference.dart';
2526
import 'package:celest_cli/src/utils/run.dart';
2627
import 'package:celest_cli/src/version.dart';
@@ -1264,8 +1265,9 @@ final class CelestProjectResolver with CelestAnalysisHelpers {
12641265
}
12651266

12661267
final schemaTypeReference = typeHelper.toReference(driftDatabaseType);
1268+
final databaseName = schemaTypeReference.symbol!;
12671269
return ast.Database(
1268-
name: schemaTypeReference.symbol!,
1270+
name: databaseName,
12691271
dartName: databaseDefinitionElement.name,
12701272
docs: databaseDefinitionElement.docLines,
12711273
schema: ast.DriftDatabaseSchema(
@@ -1274,11 +1276,11 @@ final class CelestProjectResolver with CelestAnalysisHelpers {
12741276
),
12751277
config: ast.CelestDatabaseConfig(
12761278
hostname: ast.Variable(
1277-
'CELEST_DATABASE_HOST',
1279+
'${databaseName.screamingCase}_HOST',
12781280
location: databaseDefinitionLocation,
12791281
),
12801282
token: ast.Secret(
1281-
'CELEST_DATABASE_TOKEN',
1283+
'${databaseName.screamingCase}_TOKEN',
12821284
location: databaseDefinitionLocation,
12831285
),
12841286
),

apps/cli/lib/src/utils/recase.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ extension StringRecase on String {
2424
/// The `snake_case` version of `this`.
2525
String get snakeCase => groupIntoWords().snakeCase;
2626

27+
/// The `SCREAMING_CASE` version of `this`.
28+
String get screamingCase => groupIntoWords().screamingCase;
29+
2730
// "acm-success"-> "acm success"
2831
static final _nonAlphaNumericChars = RegExp(r'[^A-Za-z0-9+]');
2932

@@ -123,4 +126,7 @@ extension type WordGroup(List<String> _group) implements List<String> {
123126

124127
/// The `snake_case` version of `this`.
125128
String get snakeCase => map((word) => word.toLowerCase()).join('_');
129+
130+
/// The `SCREAMING_CASE` version of `this`.
131+
String get screamingCase => map((word) => word.toUpperCase()).join('_');
126132
}

0 commit comments

Comments
 (0)