|
|
|
const sqlite3 = require('sqlite3').verbose(); |
|
const {runQuery, runSelectQuery} = require("./queries"); |
|
|
|
|
|
async function initializeDatabase() { |
|
try { |
|
|
|
const tables = { |
|
subscribers: `CREATE TABLE IF NOT EXISTS subscribers ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
date TEXT, |
|
time TEXT, |
|
email TEXT NOT NULL UNIQUE |
|
)`, |
|
applicants: `CREATE TABLE IF NOT EXISTS applicants ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
date TEXT, |
|
time TEXT, |
|
name TEXT NOT NULL, |
|
email TEXT NOT NULL, |
|
phone TEXT, |
|
role TEXT, |
|
experience TEXT, |
|
linkedin TEXT, |
|
resume BLOB, |
|
filename TEXT NOT NULL |
|
)`, |
|
demo_requests: `CREATE TABLE IF NOT EXISTS demo_requests ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
date TEXT, |
|
time TEXT, |
|
name TEXT NOT NULL, |
|
email TEXT NOT NULL, |
|
company TEXT, |
|
product TEXT, |
|
demo_date TEXT, |
|
slot TEXT, |
|
phone TEXT, |
|
comments TEXT |
|
)`, |
|
contact_requests: `CREATE TABLE IF NOT EXISTS contact_requests ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
date TEXT, |
|
time TEXT, |
|
name TEXT NOT NULL, |
|
email TEXT NOT NULL, |
|
phone TEXT, |
|
subject TEXT, |
|
message TEXT |
|
)`, |
|
purchases: `CREATE TABLE IF NOT EXISTS purchases ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
purchase_date TEXT, |
|
time TEXT, |
|
name TEXT NOT NULL, |
|
email TEXT NOT NULL, |
|
phone TEXT, |
|
product TEXT, |
|
subscription_plan TEXT, |
|
subscription_type TEXT |
|
)`, |
|
jobs: `CREATE TABLE IF NOT EXISTS jobs ( |
|
id INTEGER PRIMARY KEY AUTOINCREMENT, |
|
title TEXT NOT NULL, |
|
description TEXT NOT NULL, |
|
status TEXT CHECK(status IN ('Open', 'Closed')) NOT NULL DEFAULT 'Open', |
|
vacancies INTEGER NOT NULL DEFAULT 0, |
|
job_type TEXT CHECK(job_type IN ('Full-Time', 'Part-Time', 'Contract')) NOT NULL, |
|
location TEXT CHECK(location IN ('On-Site', 'Remote', 'Hybrid')) NOT NULL, |
|
date_posted TEXT NOT NULL, |
|
deadline TEXT, |
|
image_url TEXT |
|
)` |
|
}; |
|
|
|
|
|
for (const [table, query] of Object.entries(tables)) { |
|
await runQuery(query); |
|
console.log(`Table '${table}' is checked/created successfully.`); |
|
} |
|
} catch (err) { |
|
console.error('Database connection error:', err); |
|
} |
|
} |
|
|
|
module.exports = {initializeDatabase} |