-- Create a user (or more)
CREATE OR REPLACE USER nathan@'%' IDENTIFIED BY 'password';
CREATE USER 'aLeaf'@'%' IDENTIFIED BY "aLeaf";

-- Role admin, only they have permission to add others to their role
CREATE OR REPLACE ROLE admin WITH ADMIN nathan@'%';
GRANT ALL ON *.* TO admin WITH GRANT OPTION;
-- GRANT ALL PRIVILEGES ON *.* TO admin WITH GRANT OPTION;

CREATE DATABASE 'aNetwork';
GRANT ALL PRIVILEGES ON 'aNetwork'.* TO 'aLeaf'@'%'; -- The user the website is using for access

-- GRANT ALL PRIVILEGES ON *.* TO 'nathan'@'%' WITH GRANT OPTION; -- Priv, all of the belo
-- GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON *.* TO 'username'@'localhost';
-- GRANT USAGE ON *.* TO 'nathan'@'%'; -- Allows usage of the tables I guess (default on create?)

-- https://stackoverflow.com/questions/64653778/why-are-not-working-my-roles-in-my-mysql-database
SET DEFAULT ROLE admin FOR nathan; -- https://mariadb.com/kb/en/set-default-role/
-- SET ROLE ALL;
FLUSH PRIVILEGES;

-- Remove root, to prevent root login (security, yo)
DROP USER root, root@localhost

-- Create tables, and insert data into them
-- USE ecomdb; -- This is setup by default mariadb compose

-- CREATE TABLE products (id mediumint(8) unsigned NOT NULL auto_increment,Name varchar(255) default NULL,Price varchar(255) default NULL, ImageUrl varchar(255) default NULL,PRIMARY KEY (id)) AUTO_INCREMENT=1;

-- INSERT INTO products (Name,Price,ImageUrl) VALUES ("Laptop","100","c-1.png"),("Drone","200","c-2.png"),("VR","300","c-3.png"),("Tablet","50","c-5.png"),("Watch","90","c-6.png"),("Phone Covers","20","c-7.png"),("Phone","80","c-8.png"),("Laptop","150","c-4.png");
