CREATE TABLE roles(
role_id SERIAL NOT NULL,
role_name VARCHAR(20) UNIQUE NOT NULL,
CONSTRAINT roles_pk PRIMARY KEY (role_id)
);

DESCRIBE roles;


CREATE TABLE user_roles(
u_id INTEGER NOT NULL,
role_id INTEGER NOT NULL,
CONSTRAINT user_roles_pk PRIMARY KEY(u_id,role_id)
);


-- foreign key to be added to this table in alter table form  
CREATE TABLE users(
u_id SERIAL NOT NULL,
user_name VARCHAR(70) UNIQUE NOT NULL,
user_password VARCHAR(68) NOT NULL,
-- fk to uder_account 
CONSTRAINT user_table_pk PRIMARY KEY(u_id)
);


ALTER TABLE user_roles ADD CONSTRAINT user_lones_U_fk_to_user FOREIGN KEY(u_id) REFERENCES users(u_id);
ALTER TABLE user_roles ADD CONSTRAINT user_lones_R_fk_to_user FOREIGN KEY(role_id) REFERENCES roles(role_id);


INSERT INTO roles(role_id, role_name) VALUES (1, 'ROLE_admin');

SELECT * FROM users;
SELECT * FROM user_roles;
SELECT * FROM roles;
