Initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
const { Pool } = require('pg');
|
||||
require('dotenv').config();
|
||||
|
||||
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
|
||||
|
||||
async function updateDB() {
|
||||
try {
|
||||
await pool.query(`
|
||||
CREATE TABLE IF NOT EXISTS idempotency_keys (
|
||||
key VARCHAR(100) PRIMARY KEY,
|
||||
method VARCHAR(10),
|
||||
path VARCHAR(255),
|
||||
response_body JSONB,
|
||||
response_status INTEGER,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS order_drafts (
|
||||
id VARCHAR(50) PRIMARY KEY,
|
||||
subject_ref VARCHAR(100) NOT NULL,
|
||||
prescription_ref VARCHAR(50),
|
||||
items JSONB DEFAULT '[]'::jsonb,
|
||||
status VARCHAR(20) DEFAULT 'draft',
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS inventory_adjustments (
|
||||
id SERIAL PRIMARY KEY,
|
||||
batch_no VARCHAR(100) REFERENCES batches(batch_no),
|
||||
qty_delta INTEGER NOT NULL,
|
||||
reason_code VARCHAR(50) NOT NULL,
|
||||
notes TEXT,
|
||||
approved_by VARCHAR(100) NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
`);
|
||||
console.log('Core API schema updated successfully');
|
||||
} catch (err) {
|
||||
console.error('Error:', err);
|
||||
} finally {
|
||||
pool.end();
|
||||
}
|
||||
}
|
||||
|
||||
updateDB();
|
||||
Reference in New Issue
Block a user