-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreationformtable.js
More file actions
32 lines (27 loc) · 868 Bytes
/
creationformtable.js
File metadata and controls
32 lines (27 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// setup-db.js (ESM, async/await)
import sqlite3 from "sqlite3";
import { open } from "sqlite";
// Open database with sqlite (promise-based)
const db = await open({
filename: "./data.sqlite",
driver: sqlite3.Database,
});
// Enable foreign keys
await db.exec("PRAGMA foreign_keys = ON;");
// Create the table
await db.exec(`
CREATE TABLE IF NOT EXISTS user_form_steps (
relation_id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
form_id TEXT NOT NULL,
step INTEGER NOT NULL,
created_at TEXT NOT NULL DEFAULT (datetime('now')),
updated_at TEXT NOT NULL DEFAULT (datetime('now')),
FOREIGN KEY (user_id) REFERENCES users(id)
ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE (user_id, form_id)
)
`);
console.log("user_form_steps table ensured.");
// Always close when done
await db.close();