I've a simple requirement but with little experience in designing.
Each client request to rotate a photo will cost 1 cent. I need to add each request in a table for history purpose:
CREATE TABLE Rotate_Photo
(
license VARCHAR(35),
reqtype INT NOT NULL, --each will cost 1 cent
updated TIMESTAMP,
FOREIGN KEY (license)
REFERENCES customer(license)
ON DELETE CASCADE
ON UPDATE CASCADE
)ENGINE=InnoDB;
Now another Payments table will hold credit balance for each client.
CREATE TABLE Payments (
license VARCHAR(35),
Amount FLOAT(5,0) NOT NULL,
receive_date DATE NOT NULL,
updated TIMESTAMP,
FOREIGN KEY (license)
REFERENCES customer(license)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=InnoDB;
How would I know when the client has run out of balance? Given that fact that server will get many requests every second.
If a request comes then I can sum all records in Rotate_Photo to know how many requests have been received and subtract with client credit. But will it not be very inefficient?
What will be better way?