create-test-db.jsā¢1.58 kB
import sqlite3 from 'sqlite3';
import { existsSync, unlinkSync } from 'fs';
const testDbPath = './data/test.db';
// Remove existing test database if it exists
if (existsSync(testDbPath)) {
unlinkSync(testDbPath);
}
// Create new database
const db = new sqlite3.Database(testDbPath);
db.serialize(() => {
// Create books table
db.run(`CREATE TABLE books (
book_id INTEGER PRIMARY KEY,
title TEXT,
author TEXT,
code TEXT,
pub_year INTEGER,
folder_color_group TEXT
)`);
// Create paragraphs table
db.run(`CREATE TABLE paragraphs (
para_id INTEGER PRIMARY KEY,
book_id INTEGER,
content_plain TEXT,
puborder INTEGER,
refcode_long TEXT,
refcode_short TEXT,
FOREIGN KEY(book_id) REFERENCES books(book_id)
)`);
// Insert test data
db.run(`INSERT INTO books VALUES
(1, 'Test Book 1', 'Test Author', 'TB1', 2024, 'test-group'),
(2, 'Test Book 2', 'Test Author', 'TB2', 2024, 'test-group')
`);
db.run(`INSERT INTO paragraphs VALUES
(1, 1, 'This is a test paragraph about health and wellness.', 1, 'TB1:1', 'TB1:1'),
(2, 1, 'Another paragraph discussing health topics.', 2, 'TB1:2', 'TB1:2'),
(3, 2, 'This paragraph mentions health and fitness.', 1, 'TB2:1', 'TB2:1')
`);
console.log('ā
Test database created successfully');
console.log('š Database structure:');
console.log(' - books table with 2 test books');
console.log(' - paragraphs table with 3 test paragraphs');
console.log(' - All tables include health-related content for testing');
});
db.close();