forked from Bitcoindefi/OpenAO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrate.ts
More file actions
30 lines (27 loc) · 910 Bytes
/
Copy pathmigrate.ts
File metadata and controls
30 lines (27 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import fs from "fs";
import path from "path";
import pool from "./db";
async function migrate(): Promise<void> {
const schemaPath = path.resolve(__dirname, "..", "schema.sql");
const schemaSql = fs.readFileSync(schemaPath, "utf8");
await pool.query(schemaSql);
await pool.query(`
CREATE INDEX IF NOT EXISTS idx_market_listings_active_price_created
ON market_listings(price ASC, created_at ASC)
WHERE status = 'active'
`);
await pool.query(`
CREATE INDEX IF NOT EXISTS idx_market_listings_seller_active_created
ON market_listings(seller_character_id, created_at DESC)
WHERE status = 'active'
`);
console.log("Database schema applied successfully");
}
void migrate()
.catch((error) => {
console.error("Failed to apply database schema", error);
process.exit(1);
})
.finally(async () => {
await pool.end();
});