Files
cannaiq/backend/dist/db/add-jobs-table.js
2025-11-28 19:45:44 -07:00

42 lines
1.3 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const migrate_1 = require("./migrate");
async function addJobsTable() {
const client = await migrate_1.pool.connect();
try {
await client.query('BEGIN');
await client.query(`
CREATE TABLE IF NOT EXISTS jobs (
id SERIAL PRIMARY KEY,
type VARCHAR(50) NOT NULL,
status VARCHAR(50) DEFAULT 'pending',
store_id INTEGER REFERENCES stores(id) ON DELETE CASCADE,
progress INTEGER DEFAULT 0,
total_items INTEGER,
processed_items INTEGER DEFAULT 0,
error TEXT,
started_at TIMESTAMP,
completed_at TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE INDEX IF NOT EXISTS idx_jobs_status ON jobs(status);
CREATE INDEX IF NOT EXISTS idx_jobs_type ON jobs(type);
CREATE INDEX IF NOT EXISTS idx_jobs_store_id ON jobs(store_id);
`);
await client.query('COMMIT');
console.log('✅ Jobs table created successfully');
}
catch (error) {
await client.query('ROLLBACK');
console.error('❌ Failed to create jobs table:', error);
throw error;
}
finally {
client.release();
}
}
addJobsTable()
.then(() => process.exit(0))
.catch(() => process.exit(1));