-- Création de la base de données SQLite : boutique.db PRAGMA foreign_keys = ON; -- ========================= -- TABLE UTILISATEURS -- ========================= CREATE TABLE IF NOT EXISTS utilisateurs ( id INTEGER PRIMARY KEY AUTOINCREMENT, nom TEXT NOT NULL, prenom TEXT NOT NULL, email TEXT UNIQUE NOT NULL, mot_de_passe TEXT NOT NULL, created_at TEXT DEFAULT (datetime('now')) ); -- ========================= -- TABLE PRODUITS -- ========================= CREATE TABLE IF NOT EXISTS produits ( id INTEGER PRIMARY KEY AUTOINCREMENT, nom TEXT NOT NULL, marque TEXT NOT NULL, prix REAL NOT NULL, prix_barre REAL, note REAL DEFAULT 0, avis INTEGER DEFAULT 0, badge TEXT, couleur TEXT, stockage TEXT, description TEXT ); -- ========================= -- TABLE COMMANDES -- ========================= CREATE TABLE IF NOT EXISTS commandes ( id INTEGER PRIMARY KEY AUTOINCREMENT, utilisateur_id INTEGER NOT NULL, total REAL NOT NULL, statut TEXT DEFAULT 'en_cours', created_at TEXT DEFAULT (datetime('now')), FOREIGN KEY (utilisateur_id) REFERENCES utilisateurs(id) ON DELETE CASCADE ); -- ========================= -- TABLE COMMANDE ITEMS -- ========================= CREATE TABLE IF NOT EXISTS commande_items ( id INTEGER PRIMARY KEY AUTOINCREMENT, commande_id INTEGER NOT NULL, produit_id INTEGER NOT NULL, quantite INTEGER NOT NULL, prix_unitaire REAL NOT NULL, FOREIGN KEY (commande_id) REFERENCES commandes(id) ON DELETE CASCADE, FOREIGN KEY (produit_id) REFERENCES produits(id) ON DELETE CASCADE ); -- ========================= -- TABLE FAVORIS -- ========================= CREATE TABLE IF NOT EXISTS favoris ( id INTEGER PRIMARY KEY AUTOINCREMENT, utilisateur_id INTEGER NOT NULL, produit_id INTEGER NOT NULL, created_at TEXT DEFAULT (datetime('now')), FOREIGN KEY (utilisateur_id) REFERENCES utilisateurs(id) ON DELETE CASCADE, FOREIGN KEY (produit_id) REFERENCES produits(id) ON DELETE CASCADE ); -- ========================= -- TABLE PANIER -- ========================= CREATE TABLE IF NOT EXISTS panier ( id INTEGER PRIMARY KEY AUTOINCREMENT, utilisateur_id INTEGER NOT NULL, produit_id INTEGER NOT NULL, quantite INTEGER DEFAULT 1, FOREIGN KEY (utilisateur_id) REFERENCES utilisateurs(id) ON DELETE CASCADE, FOREIGN KEY (produit_id) REFERENCES produits(id) ON DELETE CASCADE ); -- ========================= -- DONNÉES EXEMPLE -- ========================= INSERT INTO produits (nom, marque, prix, prix_barre, note, avis, badge, couleur, stockage, description) VALUES ('iPhone 15 Pro', 'Apple', 1200, 1350, 4.8, 320, 'Nouveau', 'Noir Titane', '256 Go', 'Smartphone haut de gamme Apple'), ('Galaxy S24', 'Samsung', 950, 1100, 4.6, 210, 'Promo', 'Gris', '512 Go', 'Smartphone Samsung dernière génération'), ('Redmi Note 13', 'Xiaomi', 320, 380, 4.4, 150, 'Best Seller', 'Bleu', '128 Go', 'Excellent rapport qualité/prix');