So I'm new to database structure, and I am currently making an app. I wanted to run the structure by you guys to make sure this is the optimum way to build the database.
So the app, is basically for several experiments for learnings. So basically, you login, and you are presented with various tasks, then you create a session. For which you need to finish to do any other task. Each trial is recorded, and when the session is finished (determined by the number of trials, then the app returns you to the menu.
CREATE TABLE `users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`firstname` varchar(255) NOT NULL,
`lastname` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(60) NOT NULL,
`created_at` timestamp NOT NULL,
`updated_at` timestamp NOT NULL,
`remember_token` varchar(100) NOT NULL,
`status` varchar(100) NOT NULL,
`priviledges` varchar(100) NOT NULL,
`rewards` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `sessions` (
`id` int(100) NOT NULL AUTO_INCREMENT,
`user_id` int(100) NOT NULL,
`task_type` varchar(255) NOT NULL,
`firstresponse_datetime` timestamp NOT NULL,
`lastresponse_datetime` timestamp NOT NULL,
`max_trials` int(4) NOT NULL,
`current_trial` int(4) NOT NULL,
`status` int(2) NOT NULL,
`wasted_stimuli` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `trials` (
`id` int(255) NOT NULL AUTO_INCREMENT,
`session_id` int(255) NOT NULL,
`transfer` tinyint(1) NOT NULL,
`sd` varchar(255) NOT NULL,
`sample` varchar(255) NOT NULL,
`comparisons` varchar(255) NOT NULL,
`response` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
So here's the thing. I am concerned that the app is reliant on too many tables at once. Like, the general app is that, a page is presented, a post request is made and the data gets entered into the database. A page between trials is presented, then the user is redirected to a new trial page. So within a matter of a 10-15 seconds, the use will make roughly 2 trials.
My concern is that the server is a webserver, and this will be part of a php script. The trials will be INSERT, the session will be UPDATED and the user might get UPDATED to by tokens. But tokens might be part of the session table. To reduce UPDATE from 2 to 1 table only, with only 1 insert.
Also I'm concern about the wasted_stimuli row. This will basically be an array that would be updated and extended every trial. And at the beginning of every trial it is checked. So I'm either retrieving the wasted_stimuli array from sessions or I perform a SELECT sd WHERE JOIN SESSIONS AND TRIALS BY ID to session_id based on the user. and then place sd in an array.
I'm not sure what is the best standard for this.
Thanks! Any other things that could make it better would be interested in knowing.
Let me know if you have any questions