Initial commit of Step Admin panel
This commit is contained in:
36
scripts/init-db.ts
Normal file
36
scripts/init-db.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import Database from 'better-sqlite3';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const dataDir = path.resolve('./data');
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
fs.mkdirSync(dataDir, { recursive: true });
|
||||
}
|
||||
|
||||
const db = new Database(path.join(dataDir, 'app.db'));
|
||||
|
||||
db.exec(`
|
||||
CREATE TABLE IF NOT EXISTS certificates (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
device_name TEXT NOT NULL,
|
||||
subject TEXT NOT NULL,
|
||||
serial_number TEXT UNIQUE NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'active', -- 'active', 'revoked', 'expired'
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
expires_at DATETIME NOT NULL,
|
||||
revoked_at DATETIME,
|
||||
file_path TEXT NOT NULL,
|
||||
created_by TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
action TEXT NOT NULL,
|
||||
details TEXT NOT NULL,
|
||||
ip_address TEXT,
|
||||
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
created_by TEXT NOT NULL
|
||||
);
|
||||
`);
|
||||
|
||||
console.log('Database initialized successfully.');
|
||||
Reference in New Issue
Block a user