|
1 | | -import { |
2 | | - isNonEmptyArray, |
3 | | - isNonEmptyReadonlyArray, |
4 | | - NonEmptyReadonlyArray, |
5 | | -} from "../Array.js"; |
| 1 | +import { isNonEmptyArray, NonEmptyReadonlyArray } from "../Array.js"; |
6 | 2 | import { assert, assertNonEmptyReadonlyArray } from "../Assert.js"; |
7 | 3 | import { CallbackId } from "../Callbacks.js"; |
8 | 4 | import { ConsoleDep } from "../Console.js"; |
@@ -121,7 +117,6 @@ export type DbWorkerInput = |
121 | 117 | readonly type: "init"; |
122 | 118 | readonly config: Config; |
123 | 119 | readonly dbSchema: DbSchema; |
124 | | - readonly initialData: ReadonlyArray<DbChange>; |
125 | 120 | } |
126 | 121 | | { |
127 | 122 | readonly type: "mutate"; |
@@ -157,6 +152,7 @@ export type DbWorkerOutput = |
157 | 152 | | { |
158 | 153 | readonly type: "onInit"; |
159 | 154 | readonly appOwner: AppOwner; |
| 155 | + readonly isFirst: boolean; |
160 | 156 | } |
161 | 157 | | { |
162 | 158 | readonly type: "onError"; |
@@ -289,11 +285,11 @@ export const createDbWorkerForPlatform = ( |
289 | 285 | let appOwner: AppOwner; |
290 | 286 | let clock: Clock; |
291 | 287 |
|
292 | | - const versionTableExists = currentDbSchema.value.tables.some( |
| 288 | + const dbIsInitialized = currentDbSchema.value.tables.some( |
293 | 289 | (table) => table.name === "evolu_version", |
294 | 290 | ); |
295 | 291 |
|
296 | | - if (versionTableExists) { |
| 292 | + if (dbIsInitialized) { |
297 | 293 | const versionResult = sqlite.exec<{ |
298 | 294 | protocolVersion: number; |
299 | 295 | }>(sql`select protocolVersion from evolu_version limit 1;`); |
@@ -383,15 +379,11 @@ export const createDbWorkerForPlatform = ( |
383 | 379 | storage: storage.value, |
384 | 380 | }; |
385 | 381 |
|
386 | | - if ( |
387 | | - !versionTableExists && |
388 | | - isNonEmptyReadonlyArray(initMessage.initialData) |
389 | | - ) { |
390 | | - const result = applyChanges(depsWithoutSync)(initMessage.initialData); |
391 | | - if (!result.ok) return result; |
392 | | - } |
393 | | - |
394 | | - postMessage({ type: "onInit", appOwner }); |
| 382 | + postMessage({ |
| 383 | + type: "onInit", |
| 384 | + appOwner, |
| 385 | + isFirst: !dbIsInitialized, |
| 386 | + }); |
395 | 387 |
|
396 | 388 | const sync = platformDeps.createSync(platformDeps)({ |
397 | 389 | ...initMessage.config, |
|
0 commit comments