DROP TABLE IF EXISTS t_user_role;
DROP TABLE IF EXISTS t_user;
DROP TABLE IF EXISTS t_role;

CREATE TABLE t_user (
	id INT AUTO_INCREMENT PRIMARY KEY,
	username VARCHAR(25) NOT NULL,
	password VARCHAR(128) NOT NULL
);

CREATE TABLE t_role (
	id INT AUTO_INCREMENT PRIMARY KEY,
	rolename VARCHAR(25) NOT NULL
);

CREATE TABLE t_user_role (
	id INT AUTO_INCREMENT PRIMARY KEY,
	userid INT NOT NULL,
	roleid INT NOT NULL,
	FOREIGN KEY (userid) REFERENCES t_user(id),
	FOREIGN KEY (roleid) REFERENCES t_role(id)
);

INSERT INTO t_user (id, username, password) VALUES (1, 'moviesadmin', SHA2('topsecret', 512));
INSERT INTO t_user (id, username, password) VALUES (2, 'moviesuser', SHA2('topsecret', 512));

INSERT INTO t_role (id, rolename) VALUES (1, 'MoviesAdminRole');
INSERT INTO t_role (id, rolename) VALUES (2, 'MoviesUserRole');

INSERT INTO t_user_role (id, userid, roleid) VALUES (1, 1, 1);
INSERT INTO t_user_role (id, userid, roleid) VALUES (2, 2, 2);