CREATE DATABASE IF NOT EXISTS `vinted_peche` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `vinted_peche`;

DROP TABLE IF EXISTS `abonnement`;
CREATE TABLE IF NOT EXISTS `abonnement` (
  `id_followers` int(10) DEFAULT NULL,
  `id_followed` int(10) DEFAULT NULL,
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `articles`;
CREATE TABLE IF NOT EXISTS `articles` (
  `id_article` int(11) NOT NULL AUTO_INCREMENT,
  `ref_article` varchar(16) NOT NULL,
  `nom_article` varchar(30) NOT NULL,
  `detail_article` varchar(255) NOT NULL,
  `prix_article` decimal(7,2) NOT NULL,
  `image_article` varchar(255) DEFAULT NULL,
  `image_article2` varchar(200) DEFAULT NULL,
  `image_article3` varchar(200) DEFAULT NULL,
  `image_article4` varchar(200) DEFAULT NULL,
  `image_article5` varchar(200) DEFAULT NULL,
  `auteur_id` int(11) NOT NULL,
  `categorie_article` varchar(50) NOT NULL,
  `etat_article` varchar(20) NOT NULL,
  `checkout_session` text,
  `status_article` int(11) NOT NULL DEFAULT '1',
  `price_id` varchar(255) DEFAULT NULL,
  `notify` int(1) NOT NULL DEFAULT '0',
  `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id_article`),
  KEY `auteur_id` (`auteur_id`)
) ENGINE=MyISAM AUTO_INCREMENT=388 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `articles_old`;
CREATE TABLE IF NOT EXISTS `articles_old` (
  `id_article` int(11) NOT NULL,
  `id_acheteur` int(11) NOT NULL,
  `auteur_id` int(11) NOT NULL,
  `date` datetime DEFAULT CURRENT_TIMESTAMP,
  `price_id` varchar(255) NOT NULL,
  `checkout_session` text,
  `etiquette` varchar(255) DEFAULT NULL,
  `notify` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_article`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `avis_users`;
CREATE TABLE IF NOT EXISTS `avis_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `auteur_id` int(11) NOT NULL,
  `destinataire_id` int(11) NOT NULL,
  `commentaire` varchar(255) NOT NULL,
  `note` int(11) DEFAULT NULL,
  `ref_article` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=21 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `defi_list`;
CREATE TABLE IF NOT EXISTS `defi_list` (
  `defi_id` int(11) NOT NULL AUTO_INCREMENT,
  `defi_title` varchar(255) NOT NULL,
  `defi_description` varchar(255) NOT NULL,
  `defi_xp` int(11) NOT NULL,
  `defi_type` int(11) NOT NULL,
  `defi_nombre` int(11) NOT NULL,
  `defi_group` int(11) NOT NULL,
  PRIMARY KEY (`defi_id`)
) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=utf8;

INSERT INTO `defi_list` (`defi_id`, `defi_title`, `defi_description`, `defi_xp`, `defi_type`, `defi_nombre`, `defi_group`) VALUES
(1, 'Photo de profil', 'Ajoute une photo de profil ! Mets en avant ton big fish.', 1, 1, 1, 0),
(2, 'Newsletter', 'Abonnes toi à la newsletter.', 1, 1, 1, 0),
(3, 'Superbe note', 'Obtiens une note 5 étoiles suite à une transaction', 1, 1, 1, 0),
(4, 'Transactions', 'Réalise ta première transaction !', 2, 2, 1, 10),
(5, 'Transactions', 'Réalise 5 transactions.', 4, 2, 5, 10),
(6, 'Transactions', 'Réalise 10 transactions.', 6, 2, 10, 10),
(7, 'Transactions', 'Réalise 15 transactions.', 8, 2, 15, 10),
(8, 'Transactions', 'Réalise 20 transactions.', 10, 2, 20, 10),
(9, 'Négociations', 'Négocie ton premier article !', 2, 2, 1, 20),
(10, 'Négociations', 'Négocie 5 articles.', 4, 2, 5, 20),
(11, 'Négociations', 'Négocie 10 articles.', 6, 2, 10, 20),
(12, 'Négociations', 'Négocie 15 articles.', 8, 2, 15, 20),
(13, 'Négociations', 'Négocie 20 articles.', 10, 2, 20, 20),
(14, 'Réseaux sociaux', 'Suis-nous sur un de nos réseaux sociaux !', 1, 1, 1, 0),
(15, 'Parrainage', 'Parraine un ami.', 1, 1, 1, 0);
DROP TABLE IF EXISTS `defi_user`;
CREATE TABLE IF NOT EXISTS `defi_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_id` int(11) NOT NULL,
  `defi_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=67 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `images_article`;
CREATE TABLE IF NOT EXISTS `images_article` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nom_image` varchar(255) DEFAULT NULL,
  `auteur_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=418 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `level`;
CREATE TABLE IF NOT EXISTS `level` (
  `niveau` int(11) NOT NULL,
  `point_expererience` int(11) NOT NULL,
  PRIMARY KEY (`niveau`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `level` (`niveau`, `point_expererience`) VALUES
(1, 0),
(2, 10),
(3, 20),
(4, 30),
(5, 40),
(6, 60),
(7, 80),
(8, 100);
DROP TABLE IF EXISTS `like_article`;
CREATE TABLE IF NOT EXISTS `like_article` (
  `like_id` int(11) NOT NULL AUTO_INCREMENT,
  `id_article` int(11) NOT NULL,
  `id_user` int(11) NOT NULL,
  `notify` int(1) NOT NULL DEFAULT '0',
  `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`like_id`)
) ENGINE=MyISAM AUTO_INCREMENT=665 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `messages`;
CREATE TABLE IF NOT EXISTS `messages` (
  `id_message` int(11) NOT NULL AUTO_INCREMENT,
  `id_auteur` int(11) NOT NULL,
  `id_destinataire` int(11) NOT NULL,
  `message` text NOT NULL,
  `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `notify` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_message`)
) ENGINE=MyISAM AUTO_INCREMENT=476 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `offre_article`;
CREATE TABLE IF NOT EXISTS `offre_article` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `id_article` int(11) NOT NULL,
  `id_acheteur` int(11) NOT NULL,
  `nouveau_prix` decimal(7,2) NOT NULL,
  `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `message` text NOT NULL,
  `new_price_id` text,
  `statut` int(1) NOT NULL DEFAULT '0',
  `notify` int(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=178 DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `login` varchar(30) NOT NULL,
  `mail` varchar(40) NOT NULL,
  `password` varchar(64) DEFAULT NULL,
  `avatar` varchar(255) DEFAULT 'https://cdn.pixabay.com/photo/2016/08/08/09/17/avatar-1577909_960_720.png',
  `timestamp_inscription` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `localisation` varchar(255) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `niveau` int(2) NOT NULL DEFAULT '1',
  `xp_total` int(11) NOT NULL DEFAULT '0',
  `note` int(11) DEFAULT NULL,
  `birthday` date DEFAULT NULL,
  `nom` varchar(255) DEFAULT NULL,
  `prenom` varchar(255) DEFAULT NULL,
  `adresse` varchar(255) DEFAULT NULL,
  `code_postal` int(11) DEFAULT NULL,
  `ville` varchar(255) DEFAULT NULL,
  `origin` int(1) NOT NULL DEFAULT '0',
  `newsletter` int(1) NOT NULL DEFAULT '0',
  `accept_cgv` int(1) NOT NULL DEFAULT '1',
  `moderateur` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=129 DEFAULT CHARSET=utf8;
ALTER TABLE `articles` ADD FULLTEXT KEY `ft_index` (`nom_article`,`detail_article`);
COMMIT;
