diff options
author | LarsVomMars | 2020-10-02 13:37:10 +0200 |
---|---|---|
committer | LarsVomMars | 2020-10-02 13:37:14 +0200 |
commit | 6f0b965f3a1a14a959c1cde7fa2a31fb7beaf03f (patch) | |
tree | 940a1af1825d200d7092b3312c904d49401f336a | |
parent | e20b64cddc77cf07a9f2b0c27ce12ca21e61d1f3 (diff) |
Move to js initValues
-rw-r--r-- | db.js | 8 | ||||
-rw-r--r-- | tables.sql | 16 |
2 files changed, 11 insertions, 13 deletions
@@ -12,7 +12,7 @@ class DB { database: process.env.DBName, }); this.init(); - this.query("SELECT * FROM users").then((res) => { + this.query("SELECT * FROM users LIMIT 1").then((res) => { if (res.length === 0) this.initValues(); }); } @@ -37,6 +37,12 @@ class DB { initValues() { fs.readFile(__dirname + "/names.csv", "utf8", async (err, data) => { if (err) throw err; + + await this.query("INSERT INTO types (name) VALUES ('teacher'), ('puipl')"); + await this.query( + "INSERT INTO class (name) VALUES ('TGM13.1'), ('TGM13.2'), (TGTM13.1), (TGI13.1), (TGI13.2)" + ); + const classes = data.split("--"); const userPasswords = {}; console.log("Generating users"); @@ -9,10 +9,10 @@ CREATE TABLE IF NOT EXISTS theme( ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- TODO: Remove dropping -DROP TABLE IF EXISTS quotes; -DROP TABLE IF EXISTS users; -DROP TABLE IF EXISTS types; -DROP TABLE IF EXISTS class; +-- DROP TABLE IF EXISTS quotes; +-- DROP TABLE IF EXISTS users; +-- DROP TABLE IF EXISTS types; +-- DROP TABLE IF EXISTS class; CREATE TABLE IF NOT EXISTS types( id INTEGER PRIMARY KEY AUTO_INCREMENT, @@ -49,11 +49,3 @@ CREATE TABLE IF NOT EXISTS quotes( CONSTRAINT `fk_user_quote1` FOREIGN KEY (user_id) REFERENCES users (id), CONSTRAINT `fk_user_quote2` FOREIGN KEY (author_id) REFERENCES users (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -INSERT INTO types VALUES (1, "teacher"), (2, "pupil"); -INSERT INTO class VALUES - (1, "TGM13.1"), - (2, "TGM13.2"), - (3, "TGTM13.1"), - (4, "TGI13.1"), - (5, "TGI13.2"); |