okay
This commit is contained in:
37
db.js
Normal file
37
db.js
Normal file
@@ -0,0 +1,37 @@
|
||||
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 ('admin', 'admin123')`);
|
||||
}
|
||||
});
|
||||
|
||||
// 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;
|
||||
Reference in New Issue
Block a user