38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
const sqlite3 = require('sqlite3').verbose();
|
|
const path = require('path');
|
|
|
|
const dbPath = path.resolve(__dirname, 'database.sqlite');
|
|
const db = new sqlite3.Database(dbPath, (err) => {
|
|
if (err) {
|
|
console.error('Error opening database', err.message);
|
|
} else {
|
|
console.log('Connected to the SQLite database.');
|
|
|
|
// Create devices table
|
|
db.run(`CREATE TABLE IF NOT EXISTS devices (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
login TEXT UNIQUE NOT NULL,
|
|
password TEXT NOT NULL
|
|
)`, (err) => {
|
|
if (err) {
|
|
console.error('Error creating devices table', err);
|
|
} else {
|
|
// Insert a default device for testing if it doesn't exist
|
|
db.run(`INSERT OR IGNORE INTO devices (login, password) VALUES ('daragt', 'daragt4740')`);
|
|
}
|
|
});
|
|
|
|
// Create sms_queue table
|
|
db.run(`CREATE TABLE IF NOT EXISTS sms_queue (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
phone TEXT NOT NULL,
|
|
message TEXT NOT NULL,
|
|
status TEXT DEFAULT 'pending', -- pending, processing, sent, failed
|
|
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
)`);
|
|
}
|
|
});
|
|
|
|
module.exports = db;
|