Commit c50a4c579e5c6fa8530a5452ed07c02cfa8dca7a
1 parent
b40335a8
Amélioration de la BDD
Showing
2 changed files
with
68 additions
and
36 deletions
Show diff stats
BDD.sql deleted
@@ -1,36 +0,0 @@ | @@ -1,36 +0,0 @@ | ||
1 | -CREATE TABLE Utilisateurs ( | ||
2 | - login char(30) PRIMARY KEY, | ||
3 | - mdp char(255), | ||
4 | - idCarte char(8), | ||
5 | - droit integer DEFAULT '0' | ||
6 | -); | ||
7 | - | ||
8 | -CREATE TABLE Sessions ( | ||
9 | - jeton char(30) PRIMARY KEY, | ||
10 | - utilisateur char(30) REFERENCES Utilisateurs(login) | ||
11 | - date datetime DEFAULT CURRENT_TIMESTAMP | ||
12 | -); | ||
13 | - | ||
14 | -CREATE TABLE Clients ( | ||
15 | - idCarte char(8) PRIMARY KEY, | ||
16 | - solde float(7,2), | ||
17 | - decouvert boolean DEFAULT false | ||
18 | -); | ||
19 | - | ||
20 | - | ||
21 | -CREATE TABLE Prix ( | ||
22 | - produit char(30), | ||
23 | - prix float(7,2) | ||
24 | -); | ||
25 | - | ||
26 | - | ||
27 | -CREATE TABLE Transactions ( | ||
28 | - id serial PRIMARY KEY, | ||
29 | - type char(15), | ||
30 | - client char(8) REFERENCES Client(idCarte), | ||
31 | - date datetime DEFAULT CURRENT_TIMESTAMP, | ||
32 | - montant float(7,2), | ||
33 | - quantite integer(2), | ||
34 | - utilisateur char(30) REFERENCES Utilisateur(login), | ||
35 | - valide boolean DEFAULT true | ||
36 | -); |
@@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
1 | +SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; | ||
2 | +SET time_zone = "+00:00"; | ||
3 | + | ||
4 | +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; | ||
5 | +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; | ||
6 | +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; | ||
7 | +/*!40101 SET NAMES utf8mb4 */; | ||
8 | + | ||
9 | + | ||
10 | +CREATE TABLE IF NOT EXISTS `Clients` ( | ||
11 | + `idCarte` char(8) NOT NULL, | ||
12 | + `solde` float(7,2) DEFAULT NULL, | ||
13 | + `decouvert` tinyint(1) DEFAULT '0', | ||
14 | + PRIMARY KEY (`idCarte`) | ||
15 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
16 | + | ||
17 | +CREATE TABLE IF NOT EXISTS `Prix` ( | ||
18 | + `produit` char(30) DEFAULT NULL, | ||
19 | + `prix` float(7,2) DEFAULT NULL | ||
20 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
21 | + | ||
22 | +INSERT INTO `Prix` (`produit`, `prix`) VALUES | ||
23 | +('biere', 1.80); | ||
24 | + | ||
25 | +CREATE TABLE IF NOT EXISTS `Sessions` ( | ||
26 | + `jeton` char(30) NOT NULL, | ||
27 | + `utilisateur` char(30) DEFAULT NULL, | ||
28 | + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
29 | + PRIMARY KEY (`jeton`), | ||
30 | + KEY `utilisateur` (`utilisateur`) | ||
31 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
32 | + | ||
33 | +CREATE TABLE IF NOT EXISTS `Transactions` ( | ||
34 | + `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, | ||
35 | + `type` char(15) DEFAULT NULL, | ||
36 | + `client` char(8) DEFAULT NULL, | ||
37 | + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
38 | + `montant` float(7,2) DEFAULT NULL, | ||
39 | + `quantite` int(2) DEFAULT NULL, | ||
40 | + `utilisateur` char(30) DEFAULT NULL, | ||
41 | + `valide` tinyint(1) DEFAULT '1', | ||
42 | + PRIMARY KEY (`id`), | ||
43 | + KEY `client` (`client`), | ||
44 | + KEY `utilisateur` (`utilisateur`) | ||
45 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
46 | + | ||
47 | +CREATE TABLE IF NOT EXISTS `Utilisateurs` ( | ||
48 | + `login` char(30) NOT NULL, | ||
49 | + `mdp` char(255) DEFAULT NULL, | ||
50 | + `idCarte` char(8) DEFAULT NULL, | ||
51 | + `droit` int(11) DEFAULT '0', | ||
52 | + PRIMARY KEY (`login`) | ||
53 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||
54 | + | ||
55 | +INSERT INTO `Utilisateurs` (`login`, `mdp`, `idCarte`, `droit`) VALUES | ||
56 | +('default', '$2y$10$rc6Cht/F2DM4grcOcRAGBOtd.BD56kJgkC/IiGcnV6Oqa8hjRCxSW', 'OHCEE7UH', 3); | ||
57 | + | ||
58 | + | ||
59 | +ALTER TABLE `Sessions` | ||
60 | + ADD CONSTRAINT `Sessions_utilisateur` FOREIGN KEY (`utilisateur`) REFERENCES `Utilisateurs` (`login`); | ||
61 | + | ||
62 | +ALTER TABLE `Transactions` | ||
63 | + ADD CONSTRAINT `Transactions_client` FOREIGN KEY (`client`) REFERENCES `Clients` (`idCarte`), | ||
64 | + ADD CONSTRAINT `Transactions_utilisateur` FOREIGN KEY (`utilisateur`) REFERENCES `Utilisateurs` (`login`); | ||
65 | + | ||
66 | +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; | ||
67 | +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; | ||
68 | +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; |