Skip to content

Commit 418eb26

Browse files
committed
add back in schema check removed by accident
1 parent c2521de commit 418eb26

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

packages/adapter-postgres/src/index.ts

+26-5
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,33 @@ export class PostgresDatabaseAdapter
185185
async init() {
186186
await this.testConnection();
187187

188-
const schema = fs.readFileSync(
189-
path.resolve(__dirname, "../schema.sql"),
190-
"utf8"
191-
);
188+
const client = await this.pool.connect();
189+
try {
190+
await client.query("BEGIN");
191+
192+
// Check if schema already exists (check for a core table)
193+
const { rows } = await client.query(`
194+
SELECT EXISTS (
195+
SELECT FROM information_schema.tables
196+
WHERE table_name = 'rooms'
197+
);
198+
`);
192199

193-
await this.query(schema);
200+
if (!rows[0].exists) {
201+
const schema = fs.readFileSync(
202+
path.resolve(__dirname, "../schema.sql"),
203+
"utf8"
204+
);
205+
await client.query(schema);
206+
}
207+
208+
await client.query("COMMIT");
209+
} catch (error) {
210+
await client.query("ROLLBACK");
211+
throw error;
212+
} finally {
213+
client.release();
214+
}
194215
}
195216

196217
async close() {

0 commit comments

Comments
 (0)