diff --git a/database/db_scripts/create_db.sql b/database/db_scripts/create_db.sql index 343c50e..8ce4e11 100644 --- a/database/db_scripts/create_db.sql +++ b/database/db_scripts/create_db.sql @@ -1,10 +1,10 @@ CREATE TABLE `discount` ( - `deleted_at` INT(8) NOT NULL, - `name` VARCHAR(255) NOT NULL, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL, `description` TEXT NOT NULL, `discount_percent` DECIMAL(8, 2) NOT NULL, + `deleted_at` INT(8) NOT NULL, `modified_at` INT(8) NOT NULL, `created_at` INT(8) NOT NULL, `active` BOOLEAN NOT NULL @@ -101,16 +101,16 @@ CREATE TABLE `product_category` ); CREATE TABLE `user` ( - `is_active` BOOLEAN NOT NULL, + `is_active` BOOLEAN NOT NULL DEFAULT '1', `lower_name` VARCHAR(255) NOT NULL, - `email` VARCHAR(255) NOT NULL, - `passwd_hash_algo` VARCHAR(255) NOT NULL, - `modified_at` INT(8) NOT NULL, - `is_admin` BOOLEAN NOT NULL, + `email` VARCHAR(255) NOT NULL DEFAULT 'NONE', + `passwd_hash_algo` VARCHAR(255) NOT NULL DEFAULT 'NONE', + `modified_at` INT(8) NOT NULL DEFAULT '0', + `is_admin` BOOLEAN NOT NULL DEFAULT '0', `name` VARCHAR(255) NOT NULL, `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, - `created_at` INT(8) NOT NULL, - `passwd` VARCHAR(255) NOT NULL + `created_at` INT(8) NOT NULL DEFAULT '0', + `passwd` VARCHAR(255) NOT NULL DEFAULT 'NONE' ); ALTER TABLE `user` diff --git a/database/db_scripts/fill_database.sql b/database/db_scripts/fill_database.sql new file mode 100644 index 0000000..3b27652 --- /dev/null +++ b/database/db_scripts/fill_database.sql @@ -0,0 +1,13 @@ +CREATE PROCEDURE prepare_data() +BEGIN + DECLARE i INT DEFAULT 1; + + WHILE i < 100 + DO + INSERT INTO webshop.user(is_active, name, lower_name, email) + VALUES ('1', 'harry', 'potter', 'test@test.de'); + SET i = i + 1; + end while; +end; + +CALL prepare_data(); \ No newline at end of file diff --git a/database/query/get_users.js b/database/query/get_users.js deleted file mode 100644 index f899821..0000000 --- a/database/query/get_users.js +++ /dev/null @@ -1,17 +0,0 @@ -const mysql = require('mysql'); - -const connection = mysql.createConnection({ - host: "localhost", - user: "root", - password: "", - database: "webshop" -}); - -connection.connect(function (err) { - if (err) throw err; - console.log("Connected to database"); - connection.query("SELECT * FROM user", function (err, result) { - if (err) throw err; - console.log(result); - }) -}); \ No newline at end of file diff --git a/process.env b/process.env index 840a0a6..13dd02d 100644 --- a/process.env +++ b/process.env @@ -5,4 +5,4 @@ APP_PORT=3000 DB_HOST=172.0.0.1:3306 DB_USER=root DB_PASSWORD= -DB_DATABASE= +DB_DATABASE=webshop diff --git a/scripts/query/get_users.js b/scripts/query/get_users.js new file mode 100644 index 0000000..3f80d31 --- /dev/null +++ b/scripts/query/get_users.js @@ -0,0 +1,17 @@ +const mysql = require('mysql'); + +const connection = mysql.createConnection({ + host: "localhost", + user: "root", + password: "", + database: "webshop" +}) + +connection.connect(function (err) { + if (err) throw err + console.log("Connected to database") + connection.query("SELECT * FROM user WHERE ID = 1", function (err, result) { + if (err) throw err + console.log(result) + }) +}) \ No newline at end of file