Initial commit
This commit is contained in:
parent
32184a54ce
commit
a18a0e9b7a
31 changed files with 8180 additions and 0 deletions
46
backend/database.js
Normal file
46
backend/database.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
const sqlite3 = require('sqlite3').verbose();
|
||||
const path = require('path');
|
||||
|
||||
const dbPath = path.resolve(__dirname, 'cinematch.db');
|
||||
const db = new sqlite3.Database(dbPath);
|
||||
|
||||
db.serialize(() => {
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
username TEXT UNIQUE,
|
||||
password TEXT,
|
||||
code TEXT UNIQUE NOT NULL,
|
||||
partner_code TEXT,
|
||||
genres TEXT
|
||||
)
|
||||
`);
|
||||
|
||||
// Add genres column if it doesn't exist (for existing db)
|
||||
db.run(`ALTER TABLE users ADD COLUMN genres TEXT`, (err) => {
|
||||
// Ignore error if column already exists
|
||||
});
|
||||
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS swipes (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
movie_id INTEGER,
|
||||
direction TEXT,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id),
|
||||
UNIQUE(user_id, movie_id)
|
||||
)
|
||||
`);
|
||||
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS watched (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER,
|
||||
movie_id INTEGER,
|
||||
FOREIGN KEY(user_id) REFERENCES users(id),
|
||||
UNIQUE(user_id, movie_id)
|
||||
)
|
||||
`)
|
||||
});
|
||||
|
||||
module.exports = db;
|
||||
Loading…
Add table
Add a link
Reference in a new issue