create database Hobby;

use hobby;

create table roles
(
    Role        varchar(50) charset utf8mb3  not null,
    CreatedBy   varchar(200) charset utf8mb3 not null,
    CreatedDate datetime                   not null,
    constraint role_pk
        primary key (Role)
);

create table users
(
    UserName    varchar(50) charset utf8mb3 not null
        primary key,
    Password    varchar(50) charset utf8mb3 not null,
    Role        varchar(50) charset utf8mb3 not null,
    IsActive    int default 1               not null,
    CreatedBy   varchar(50) charset utf8mb3 not null,
    CreatedDate datetime                    not null,
    Email       varchar(50)                 null,
    constraint users_Email_uindex
        unique (Email),
    constraint userRole_fk
        foreign key (Role) references roles (Role)
);


INSERT INTO hobby.users (UserName, Password, Role, IsActive, CreatedBy, CreatedDate, Email) VALUES
('Colin ', 'Waffle', 'Admin', 1, 'Jacob', '2021-12-13 04:27:42', null),
('Danny', 'Spartan', 'Admin', 1, 'Jacob', '2021-12-13 04:29:54', null),
('Jacob', 'Teamhobby1234', 'Admin', 1, 'SystemCreator', '2021-12-13 03:25:14', null),
('Long', 'Joystick', 'regular', 1, 'Jacob', '2021-12-13 04:29:57', null),
('Rifat', '1234', 'Admin', 1, 'Jacob', '2021-12-13 04:29:55', null);


INSERT INTO hobby.roles (Role, CreatedBy, CreatedDate) VALUES 
('Admin', 'Jacob', '2021-12-13 03:25:14'),
('regular', 'Jacob', '2021-12-13 03:25:14');


SET Global innodb_file_per_table=ON;

SET GLOBAL innodb_default_row_format='dynamic';

SET GLOBAL innodb_compression_algorithm='zlib';



CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);

CREATE DATABASE testDB;

-- Hobby DDL
-- Log level table
create table LogLevel
(
    LvName    varchar(50)  not null,
    LvComment varchar(500) not null,
    constraint LogLevel_pk
        primary key (LvName)
);

-- Log categories table
create table LogCategories
(
    catName varchar(50) not null,
    catComment varchar(255) not null,
    constraint LogCategories_pk primary key (catName)
);

-- DDL for log table
create table Log
(
    LtimeStamp datetime default CURRENT_TIMESTAMP null,
    logID      int auto_increment                 not null,
    LvName     varchar(50)                        not null,
    catName    varchar(50)                        not null,
    userOP     varchar(50)                        not null,
    logMessage varchar(255)                       not null,

    constraint LogLvName_fk foreign key (LvName) references loglevel (LvName),
    constraint LogCatName_fk foreign key (catName) references logcategories (catName),
    constraint Log_pk primary key (logID)

);

-- Dummy data for testing purposes
-- Log categories data
INSERT into logcategories(catName, catComment) values
    ('View', 'view layer'),
    ('Business', 'business layer'),
    ('Server', 'server layer'),
    ('Data', 'data layer');

-- Log level data
INSERT into loglevel(lvname, lvcomment) values
    ('Info', 'some sys flow'),
    ('Debug', 'info for fixing bugs'),
    ('Warning', 'track system failure'),
    ('Error', 'some sys errors');

-- Log table data
INSERT into log(lvname, catname, userop, logmessage) values
    ('Info', 'View', 'create some projects', 'new account created'),
    ('Info', 'Business', 'create some projects', 'new projects made'),
    ('Info', 'View', 'log out', 'log out successful'),
    ('Info', 'Business', 'log in', 'log in successfully'),
    ('Info', 'View', 'search for projects', 'result return');




