Skip to content

Commit 51a7586

Browse files
committed
feat: refine MemoryEnvironmentDatabaseAdapter to eliminate unnecessary file writes and clarify storage behavior
1 parent c2bbde1 commit 51a7586

1 file changed

Lines changed: 8 additions & 26 deletions

File tree

packages/services/service-tenant/src/environment-provisioning.ts

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,40 +140,21 @@ export class LocalSQLiteEnvironmentDatabaseAdapter implements EnvironmentDatabas
140140
}
141141

142142
/**
143-
* In-memory environment adapter. Writes a small JSON marker file per
144-
* environment under `baseDir` so operators can at least see evidence on
145-
* disk that the env was provisioned (the real storage is ephemeral memory).
143+
* In-memory environment adapter. Storage is ephemeral by design — the
144+
* control-plane ObjectQL driver (which IS the memory driver) already
145+
* persists the `sys__environment` record into `memory-driver.json` in
146+
* its own format. This adapter only needs to return a stable URL; it must
147+
* not write any separate marker files.
146148
*/
147149
export class MemoryEnvironmentDatabaseAdapter implements EnvironmentDatabaseAdapter {
148150
readonly driver: DatabaseDriver = 'memory';
149151

150-
constructor(private readonly baseDir: string = '.objectstack/data/environments') {}
151-
152152
async createDatabase(params: {
153153
environmentId: string;
154154
databaseName: string;
155155
region: string;
156156
storageLimitMb: number;
157157
}): Promise<{ databaseUrl: string; plaintextSecret: string }> {
158-
const { mkdirSync, writeFileSync } = await import('node:fs');
159-
const { resolve } = await import('node:path');
160-
const markerPath = resolve(this.baseDir, `${params.databaseName}.memory.json`);
161-
mkdirSync(this.baseDir, { recursive: true });
162-
writeFileSync(
163-
markerPath,
164-
JSON.stringify(
165-
{
166-
driver: 'memory',
167-
environmentId: params.environmentId,
168-
databaseName: params.databaseName,
169-
region: params.region,
170-
storageLimitMb: params.storageLimitMb,
171-
provisionedAt: new Date().toISOString(),
172-
},
173-
null,
174-
2,
175-
),
176-
);
177158
return {
178159
databaseUrl: `memory://${params.databaseName}`,
179160
plaintextSecret: '',
@@ -548,8 +529,9 @@ export class EnvironmentProvisioningService {
548529
* directly when a caller picks a driver.
549530
*
550531
* Selection rules:
551-
* - Always register the `memory` adapter (writes a `.memory.json` marker
552-
* file per environment so operators can see what was provisioned).
532+
* - Always register the `memory` adapter (returns a `memory://` URL;
533+
* the control-plane ObjectQL driver handles persisting the record into
534+
* `memory-driver.json` in its native format).
553535
* - Always register the `sqlite` adapter (writes a `.db` file per env
554536
* under `.objectstack/data/environments/`).
555537
* - For the `turso` key:

0 commit comments

Comments
 (0)