@axiom-lattice/pg-stores 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +16 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +47 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/migrations/migration.ts +45 -28
- package/src/stores/PostgreSQLThreadStore.ts +20 -2
|
@@ -36,6 +36,7 @@ export class PostgreSQLThreadStore implements ThreadStore {
|
|
|
36
36
|
private migrationManager: MigrationManager;
|
|
37
37
|
private initialized: boolean = false;
|
|
38
38
|
private ownsPool: boolean = true;
|
|
39
|
+
private initPromise: Promise<void> | null = null; // Promise-based lock to prevent concurrent initialization
|
|
39
40
|
|
|
40
41
|
constructor(options: PostgreSQLThreadStoreOptions) {
|
|
41
42
|
// Create Pool from config
|
|
@@ -69,14 +70,31 @@ export class PostgreSQLThreadStore implements ThreadStore {
|
|
|
69
70
|
|
|
70
71
|
/**
|
|
71
72
|
* Initialize the store and run migrations
|
|
73
|
+
* Uses a promise-based lock to prevent concurrent initialization
|
|
72
74
|
*/
|
|
73
75
|
async initialize(): Promise<void> {
|
|
76
|
+
// If already initialized, return immediately
|
|
74
77
|
if (this.initialized) {
|
|
75
78
|
return;
|
|
76
79
|
}
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
this.
|
|
81
|
+
// If initialization is in progress, wait for it
|
|
82
|
+
if (this.initPromise) {
|
|
83
|
+
return this.initPromise;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Start initialization and store the promise
|
|
87
|
+
this.initPromise = (async () => {
|
|
88
|
+
try {
|
|
89
|
+
await this.migrationManager.migrate();
|
|
90
|
+
this.initialized = true;
|
|
91
|
+
} finally {
|
|
92
|
+
// Clear the promise after completion (success or failure)
|
|
93
|
+
this.initPromise = null;
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
|
|
97
|
+
return this.initPromise;
|
|
80
98
|
}
|
|
81
99
|
|
|
82
100
|
/**
|