-- phpMyAdmin SQL Dump
-- version 5.2.2
-- https://www.phpmyadmin.net/
--
-- Hôte : salagombooking.mysql.db
-- Généré le : mer. 08 avr. 2026 à 19:56
-- Version du serveur : 8.4.8-8
-- Version de PHP : 8.1.33

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Base de données : `salagombooking`
--

-- --------------------------------------------------------

--
-- Structure de la table `app_config`
--

CREATE TABLE `app_config` (
  `id` bigint NOT NULL,
  `property_id` bigint DEFAULT NULL,
  `unit_id` bigint DEFAULT NULL,
  `name` varchar(128) NOT NULL,
  `value` varchar(2048) DEFAULT NULL,
  `description` varchar(255) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Déchargement des données de la table `app_config`
--

INSERT INTO `app_config` (`id`, `property_id`, `unit_id`, `name`, `value`, `description`, `updated_at`) VALUES
(1, NULL, NULL, 'ui.channels.allowed_ids', '[1]', 'OBLIGATOIRE - Liste d’IDs channel visibles []', '2026-01-24 19:35:14'),
(2, NULL, NULL, 'ui.channels.mode', 'replace', 'OBLIGATOIRE - replace|merge', '2026-01-24 19:35:14'),
(3, NULL, NULL, 'pricing.mode', 'total', 'OBLIGATOIRE - total|split', '2026-01-24 19:35:14'),
(4, NULL, NULL, 'pricing.included_persons_total', NULL, 'INT si mode total', '2025-10-24 10:30:32'),
(5, NULL, NULL, 'pricing.extra_person_nightly', NULL, 'DECIMAL si mode total', '2025-10-24 10:30:32'),
(6, NULL, NULL, 'pricing.included_adults', NULL, 'INT si mode split', '2025-10-24 10:30:32'),
(7, NULL, NULL, 'pricing.included_children', NULL, 'INT si mode split', '2025-10-24 10:30:32'),
(8, NULL, NULL, 'pricing.extra_adult_nightly', NULL, 'DECIMAL si mode split', '2025-10-24 10:30:32'),
(9, NULL, NULL, 'pricing.extra_child_nightly', NULL, 'DECIMAL si mode split', '2025-10-24 10:30:32'),
(15, NULL, NULL, 'pricing.day', '[]', 'Liste des nuitées editables (JSON)', '2025-12-06 13:15:47'),
(22, NULL, NULL, 'stripe.application_fee_percent', '3.5', 'Commission plateforme Stripe (%) (ex: 3.5)', '2026-01-24 19:38:25'),
(23, NULL, NULL, 'stripe.publishable_key', NULL, 'Clé Stripe publishable (pk_test_/pk_live_)', '2026-01-24 19:35:14'),
(24, NULL, NULL, 'stripe.secret_key', NULL, 'Clé Stripe secret (sk_test_/sk_live_) (fallback)', '2026-01-24 19:35:14'),
(25, NULL, NULL, 'stripe.webhook_secret', NULL, 'Webhook signing secret (whsec_...)', '2026-01-26 09:42:00');

-- --------------------------------------------------------

--
-- Structure de la table `booking`
--

CREATE TABLE `booking` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `customer_id` bigint NOT NULL,
  `booking_rule_id` bigint DEFAULT NULL,
  `channel_id` bigint NOT NULL,
  `total_amount` decimal(10,2) DEFAULT NULL,
  `platform_commission_amount` decimal(10,2) DEFAULT NULL,
  `lodging_amount` decimal(10,2) DEFAULT NULL,
  `extras_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `tax_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `message` varchar(500) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `external_source` varchar(50) DEFAULT NULL,
  `external_uid` varchar(255) DEFAULT NULL,
  `external_raw` json DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Structure de la table `booking_guest`
--

CREATE TABLE `booking_guest` (
  `id` bigint NOT NULL,
  `reservation_unit_id` bigint NOT NULL,
  `type` enum('adulte','enfant','bebe') NOT NULL,
  `age` int DEFAULT NULL,
  `nom` varchar(100) DEFAULT NULL,
  `prenom` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `booking_payment`
--

CREATE TABLE `booking_payment` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `booking_id` bigint NOT NULL,
  `amount` decimal(10,2) NOT NULL,
  `currency` char(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EUR',
  `paid_at` datetime NOT NULL,
  `method` enum('card','cash','bank_transfer','check','voucher','other','channel') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'other',
  `status` enum('captured','partial_capture','pending','failed','refunded','voided') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'captured',
  `external_ref` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `notes` text COLLATE utf8mb4_unicode_ci,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Structure de la table `booking_rule`
--

CREATE TABLE `booking_rule` (
  `id` bigint NOT NULL,
  `name` varchar(100) DEFAULT NULL,
  `deposit_type` enum('percentage','fixed') DEFAULT 'percentage',
  `deposit_value` decimal(10,2) DEFAULT NULL,
  `balance_days` int DEFAULT '30',
  `cancellation_policy` text,
  `security_deposit` decimal(10,2) DEFAULT '0.00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `booking_status`
--

CREATE TABLE `booking_status` (
  `id` bigint NOT NULL,
  `booking_unit_id` bigint NOT NULL,
  `status_id` bigint NOT NULL,
  `changed_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `changed_by` bigint DEFAULT NULL,
  `note` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `booking_status_type`
--

CREATE TABLE `booking_status_type` (
  `id` bigint NOT NULL,
  `code` varchar(32) NOT NULL,
  `label` varchar(64) NOT NULL,
  `color` char(7) NOT NULL,
  `sort_order` tinyint NOT NULL DEFAULT '0',
  `is_blocking` tinyint(1) NOT NULL DEFAULT '0',
  `is_final` tinyint(1) NOT NULL DEFAULT '0',
  `active_back` tinyint(1) NOT NULL DEFAULT '1',
  `active_front` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Déchargement des données de la table `booking_status_type`
--

INSERT INTO `booking_status_type` (`id`, `code`, `label`, `color`, `sort_order`, `is_blocking`, `is_final`, `active_back`, `active_front`) VALUES
(0, 'libre', 'Libre', '#ffffff', 0, 0, 0, 1, 1),
(1, 'demande', 'Demande', '#6c757d', 10, 0, 0, 1, 0),
(2, 'prereserve', 'Préréservé', '#ffc107', 20, 1, 0, 1, 0),
(3, 'reserve', 'Réservé', '#198754', 30, 1, 0, 1, 1),
(4, 'annule', 'Annulé', '#dc3545', 40, 0, 1, 1, 0);

-- --------------------------------------------------------

--
-- Structure de la table `booking_unit`
--

CREATE TABLE `booking_unit` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `booking_id` bigint NOT NULL,
  `unit_id` bigint NOT NULL,
  `cleaning` tinyint(1) DEFAULT '0',
  `sheets` tinyint(1) DEFAULT '0',
  `towels` tinyint(1) DEFAULT '0',
  `checkin` date NOT NULL,
  `checkout` date NOT NULL,
  `lodging_amount` decimal(10,2) DEFAULT NULL,
  `extras_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `tax_amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `total_amount` decimal(10,2) DEFAULT NULL,
  `platform_commission_amount` decimal(10,2) DEFAULT NULL,
  `status_id` bigint DEFAULT NULL,
  `adults` int NOT NULL DEFAULT '0',
  `children` int NOT NULL DEFAULT '0',
  `babies` int NOT NULL DEFAULT '0',
  `pets` int NOT NULL DEFAULT '0',
  `external_source` varchar(50) DEFAULT NULL,
  `external_uid` varchar(255) DEFAULT NULL,
  `external_raw` json DEFAULT NULL,
  `meta_info` json DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Structure de la table `booking_unit_charge_choice`
--

CREATE TABLE `booking_unit_charge_choice` (
  `booking_unit_id` bigint NOT NULL,
  `charge_catalog_id` bigint NOT NULL,
  `enabled` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Structure de la table `channel`
--

CREATE TABLE `channel` (
  `id` int NOT NULL,
  `code` varchar(50) NOT NULL,
  `name` varchar(100) NOT NULL,
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `allow_charge_recalc` tinyint(1) NOT NULL DEFAULT '1',
  `auto_create_payment` tinyint(1) NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Déchargement des données de la table `channel`
--

INSERT INTO `channel` (`id`, `code`, `name`, `active`, `created_at`, `allow_charge_recalc`, `auto_create_payment`) VALUES
(1, 'direct', 'Direct', 1, '2025-10-03 10:57:30', 1, 0),
(2, 'pitchup', 'Pitchup', 0, '2025-10-03 16:08:55', 0, 1),
(3, 'campspace', 'Campspace', 0, '2025-10-04 18:55:20', 0, 0),
(4, 'vansite', 'Vansite', 0, '2025-10-04 18:55:20', 1, 0),
(5, 'cybevasion', 'Cybevasion', 0, '2025-10-04 18:56:03', 1, 0),
(6, 'booking', 'Booking', 1, '2025-10-04 18:56:03', 0, 1);

-- --------------------------------------------------------

--
-- Structure de la table `channel_import_log`
--

CREATE TABLE `channel_import_log` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `channel_id` int NOT NULL,
  `unit_id` bigint NOT NULL,
  `external_uid` varchar(255) NOT NULL,
  `action` enum('created','updated','cancelled','skipped','conflict') NOT NULL,
  `message` text,
  `occurred_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `raw_json` json DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `channel_mapping`
--

CREATE TABLE `channel_mapping` (
  `id` int NOT NULL,
  `property_id` bigint DEFAULT NULL,
  `channel_id` int NOT NULL,
  `external_key` varchar(100) NOT NULL,
  `target_table` enum('customer','booking','booking_unit','booking_payment') NOT NULL,
  `target_field` varchar(100) NOT NULL,
  `cast_type` enum('string','int','float','bool','date','json','enum') NOT NULL DEFAULT 'string',
  `regex` varchar(255) DEFAULT NULL,
  `enum_map_json` json DEFAULT NULL,
  `default_value` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Déchargement des données de la table `channel_mapping`
--

INSERT INTO `channel_mapping` (`id`, `property_id`, `channel_id`, `external_key`, `target_table`, `target_field`, `cast_type`, `regex`, `enum_map_json`, `default_value`) VALUES
(1, NULL, 2, 'X-PU-ADULTS', 'booking_unit', 'adults', 'int', NULL, NULL, NULL),
(2, NULL, 2, 'X-PU-CHILDREN', 'booking_unit', 'children', 'int', NULL, NULL, NULL),
(3, NULL, 2, 'X-PU-INFANTS', 'booking_unit', 'babies', 'int', NULL, NULL, NULL),
(4, NULL, 2, 'X-PU-PETS', 'booking_unit', 'pets', 'int', NULL, NULL, NULL),
(5, NULL, 2, 'X-PU-TELEPHONE', 'customer', 'phone', 'string', NULL, NULL, NULL),
(6, NULL, 2, 'X-PU-ADDRESS', 'customer', 'address', 'string', '/^\\s*(.*?)\\s*(?:\\\\\\\\,|,)\\s*/u', NULL, NULL),
(7, NULL, 2, 'X-PU-STATUS', 'booking', 'status_code', 'enum', NULL, '{\"Annulé\": \"annule\", \"Demande\": \"demande\", \"Confirmé\": \"reserve\"}', NULL),
(8, NULL, 2, 'ORGANIZER', 'customer', 'email', 'string', '/^MAILTO:(.+)$/i', NULL, NULL),
(9, NULL, 2, 'DESCRIPTION', 'customer', 'name', 'string', '/Name:\\s*([^\\r\\n\\\\]+)/i', NULL, NULL),
(10, NULL, 3, 'FIRSTNAME', 'customer', 'name', 'string', NULL, NULL, NULL),
(11, NULL, 3, 'ORGANIZER', 'customer', 'email', 'string', '/^MAILTO:(.+)$/i', NULL, NULL),
(12, NULL, 3, 'X-PU-ADDRESS', 'customer', 'address', 'string', NULL, NULL, NULL),
(13, NULL, 3, 'X-PU-ADULTS', 'booking_unit', 'adults', 'int', NULL, NULL, NULL),
(14, NULL, 3, 'X-PU-CHILDREN', 'booking_unit', 'children', 'int', NULL, NULL, NULL),
(15, NULL, 3, 'X-PU-INFANTS', 'booking_unit', 'babies', 'int', NULL, NULL, NULL),
(16, NULL, 3, 'X-PU-PETS', 'booking_unit', 'pets', 'int', NULL, NULL, NULL),
(17, NULL, 3, 'X-PU-STATUS', 'booking', 'status_code', 'enum', NULL, '{\"Annulé\": \"annule\", \"Demande\": \"demande\", \"Confirmé\": \"reserve\"}', NULL),
(18, NULL, 3, 'X-PU-TELEPHONE', 'customer', 'phone', 'string', NULL, NULL, NULL),
(19, NULL, 2, 'X-PU-REMAINDER', 'booking_unit', 'total_amount', 'float', NULL, NULL, NULL),
(20, NULL, 2, 'X-PU-COMMISSION', 'booking_unit', 'platform_commission_amount', 'float', NULL, NULL, NULL),
(21, NULL, 2, 'X-PU-REMAINDER', 'booking', 'total_amount', 'float', NULL, NULL, NULL),
(22, NULL, 2, 'X-PU-COMMISSION', 'booking', 'platform_commission_amount', 'float', NULL, NULL, NULL),
(23, NULL, 2, 'X-PU-REMAINDER', 'booking_unit', 'lodging_amount', 'float', NULL, NULL, NULL),
(24, NULL, 2, 'X-PU-REMAINDER', 'booking', 'lodging_amount', 'float', NULL, NULL, NULL),
(25, NULL, 2, 'X-PU-REMAINDER', 'booking_payment', 'amount', 'float', NULL, NULL, NULL),
(26, NULL, 2, 'X-PU-PAYMENT-STATUS', 'booking_payment', 'status', 'enum', NULL, '{\"paid\": \"captured\", \"unpaid\": \"pending\", \"partial\": \"partial_capture\", \"paid_immediate\": \"captured\"}', NULL),
(27, NULL, 2, 'X-PU-ID', 'booking_payment', 'external_ref', 'string', NULL, NULL, NULL),
(28, NULL, 2, 'X-PU-ESTIMATED-TIME-OF-ARRIVAL', 'booking_unit', 'meta_info', 'json', NULL, NULL, NULL),
(29, NULL, 2, 'X-PU-TYPE-AND-SIZE-OF-UNIT', 'booking_unit', 'meta_info', 'json', NULL, NULL, NULL),
(30, NULL, 2, 'X-PU-VEHICLE-REGISTRATION-NUMBER', 'booking_unit', 'meta_info', 'json', NULL, NULL, NULL),
(31, NULL, 2, 'X-PU-SPECIAL-REQUESTS', 'booking_unit', 'meta_info', 'json', NULL, NULL, NULL),
(32, NULL, 2, 'X-PU-ADDRESS', 'customer', 'country', 'string', '/(?:\\\\\\\\,|,)\\s*([^\\\\\\\\,]+)\\s*$/u', NULL, NULL),
(33, NULL, 2, 'X-PU-ADDRESS', 'customer', 'city', 'string', '/^\\s*.*?\\s*(?:\\\\\\\\,|,)\\s*(.*?)\\s*(?:\\\\\\\\,|,)\\s*/u', NULL, NULL),
(34, NULL, 2, 'X-PU-ADDRESS', 'customer', 'postal_code', 'string', '/^\\s*.*?\\s*(?:\\\\\\\\,|,)\\s*.*?\\s*(?:\\\\\\\\,|,)\\s*([^\\\\\\\\,]+?)\\s*(?:\\\\\\\\,|,)\\s*/u', NULL, NULL);

-- --------------------------------------------------------

--
-- Structure de la table `channel_unit`
--

CREATE TABLE `channel_unit` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `channel_id` int NOT NULL,
  `unit_id` bigint NOT NULL,
  `ics_url` varchar(1024) DEFAULT NULL,
  `ics_path` varchar(1024) DEFAULT NULL,
  `active` tinyint(1) NOT NULL DEFAULT '1',
  `last_etag` varchar(255) DEFAULT NULL,
  `last_modified` datetime DEFAULT NULL,
  `last_hash` char(64) DEFAULT NULL,
  `last_import_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `charge_booking`
--

CREATE TABLE `charge_booking` (
  `id` bigint NOT NULL,
  `booking_unit_id` bigint NOT NULL,
  `charge_catalog_id` bigint DEFAULT NULL,
  `type` enum('loyer','frais','taxe_sejour','remise','menage','drap') CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
  `label` varchar(150) NOT NULL,
  `quantity` decimal(10,2) DEFAULT '1.00',
  `unit_amount` decimal(10,2) NOT NULL,
  `total_amount` decimal(10,2) NOT NULL,
  `exclude_revenue` tinyint(1) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `charge_catalog`
--

CREATE TABLE `charge_catalog` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `unit_id` bigint NOT NULL,
  `label` varchar(100) NOT NULL,
  `description` text,
  `amount` decimal(10,2) NOT NULL,
  `calc_period` enum('per_stay','per_night') DEFAULT NULL,
  `calc_unit` enum('flat','per_unit','per_occupant','per_adult','per_child','per_baby','per_pet') DEFAULT NULL,
  `valid_from` date NOT NULL DEFAULT '1970-01-01',
  `valid_to` date DEFAULT NULL,
  `mandatory` tinyint(1) DEFAULT '0',
  `active` tinyint(1) DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Structure de la table `customer`
--

CREATE TABLE `customer` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `name` varchar(100) NOT NULL,
  `first_name` varchar(100) DEFAULT NULL,
  `email` varchar(190) DEFAULT NULL,
  `phone` varchar(40) DEFAULT NULL,
  `address` varchar(255) DEFAULT NULL,
  `postal_code` varchar(20) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `country` char(2) DEFAULT 'FR',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------

--
-- Structure de la table `housekeeping_task`
--

CREATE TABLE `housekeeping_task` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `unit_id` bigint NOT NULL,
  `booking_id` bigint DEFAULT NULL,
  `type` enum('menage','inspection','linge') NOT NULL,
  `statut` enum('a_faire','en_cours','terminee') DEFAULT 'a_faire',
  `echeance` datetime NOT NULL,
  `notes` text
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `maintenance_ticket`
--

CREATE TABLE `maintenance_ticket` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `unit_id` bigint NOT NULL,
  `description` text NOT NULL,
  `status` enum('open','in_progress','resolved') DEFAULT 'open',
  `priority` enum('low','normal','high') DEFAULT 'normal',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `property`
--

CREATE TABLE `property` (
  `id` bigint NOT NULL,
  `name` varchar(150) NOT NULL,
  `login` varchar(100) NOT NULL,
  `password_hash` varchar(255) NOT NULL,
  `address` varchar(255) DEFAULT NULL,
  `city` varchar(100) DEFAULT NULL,
  `postal_code` varchar(20) DEFAULT NULL,
  `country` char(2) DEFAULT 'FR',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
  `api_key` char(64) NOT NULL,
  `api_secret` char(64) NOT NULL,
  `allowed_domains` text,
  `active` tinyint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `rate_calendar`
--

CREATE TABLE `rate_calendar` (
  `id` bigint UNSIGNED NOT NULL,
  `property_id` bigint NOT NULL,
  `unit_id` bigint NOT NULL,
  `channel_id` bigint NOT NULL DEFAULT '0',
  `day` date NOT NULL,
  `stop_sell` tinyint(1) NOT NULL DEFAULT '0',
  `cta` tinyint(1) NOT NULL DEFAULT '0',
  `ctd` tinyint(1) NOT NULL DEFAULT '0',
  `min_stay` int NOT NULL DEFAULT '1',
  `max_stay` int NOT NULL DEFAULT '30',
  `price_n1` decimal(10,2) DEFAULT NULL,
  `price_n2` decimal(10,2) DEFAULT NULL,
  `price_n3` decimal(10,2) DEFAULT NULL,
  `price_n4` decimal(10,2) DEFAULT NULL,
  `price_n5` decimal(10,2) DEFAULT NULL,
  `price_n6` decimal(10,2) DEFAULT NULL,
  `price_n7` decimal(10,2) DEFAULT NULL,
  `price_n14` decimal(10,2) DEFAULT NULL,
  `price_n21` decimal(10,2) DEFAULT NULL,
  `price_n28` decimal(10,2) DEFAULT NULL,
  `included_persons_total` int DEFAULT NULL,
  `included_adults` int DEFAULT NULL,
  `included_children` int DEFAULT NULL,
  `extra_person_nightly` decimal(10,2) DEFAULT NULL,
  `extra_adult_nightly` decimal(10,2) DEFAULT NULL,
  `extra_child_nightly` decimal(10,2) DEFAULT NULL,
  `updated_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `status_transition`
--

CREATE TABLE `status_transition` (
  `from_status_id` bigint NOT NULL,
  `to_status_id` bigint NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

--
-- Déchargement des données de la table `status_transition`
--

INSERT INTO `status_transition` (`from_status_id`, `to_status_id`) VALUES
(1, 2),
(1, 3),
(2, 3),
(1, 4),
(2, 4),
(3, 4);

-- --------------------------------------------------------

--
-- Structure de la table `stripe_event`
--

CREATE TABLE `stripe_event` (
  `id` bigint NOT NULL,
  `stripe_event_id` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `type` varchar(128) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created` int DEFAULT NULL,
  `livemode` tinyint(1) NOT NULL DEFAULT '0',
  `stripe_account_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `raw_json` json DEFAULT NULL,
  `received_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Structure de la table `stripe_payment`
--

CREATE TABLE `stripe_payment` (
  `id` bigint NOT NULL,
  `booking_payment_id` bigint NOT NULL,
  `stripe_payment_intent_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stripe_charge_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stripe_event_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `stripe_connected_account_id` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `livemode` tinyint(1) NOT NULL DEFAULT '0',
  `amount_cents` int DEFAULT NULL,
  `currency` char(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EUR',
  `application_fee_cents` int DEFAULT NULL,
  `stripe_status` varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `raw_json` json DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;


-- --------------------------------------------------------


-- --------------------------------------------------------

--
-- Structure de la table `unit`
--

CREATE TABLE `unit` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `name` varchar(150) NOT NULL,
  `capacity` int DEFAULT '2',
  `rooms` int DEFAULT '1',
  `bathrooms` int DEFAULT '1',
  `active` tinyint(1) DEFAULT '1',
  `ics_enabled` tinyint(1) NOT NULL DEFAULT '0',
  `ics_token` char(32) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Structure de la table `user`
--

CREATE TABLE `user` (
  `id` bigint NOT NULL,
  `property_id` bigint NOT NULL,
  `name` varchar(100) NOT NULL,
  `email` varchar(150) NOT NULL,
  `password` varchar(255) NOT NULL,
  `active` tinyint(1) DEFAULT '1',
  `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

-- --------------------------------------------------------

--
-- Index pour les tables déchargées
--

--
-- Index pour la table `app_config`
--
ALTER TABLE `app_config`
    ADD PRIMARY KEY (`id`),
    ADD UNIQUE KEY `uk_appcfg` ((COALESCE(`property_id`, 0)),(COALESCE(`unit_id`, 0)) ),
  ADD KEY `idx_appcfg_prop_name` (`property_id`,`name`),
  ADD KEY `idx_appcfg_unit_name` (`unit_id`,`name`);

--
-- Index pour la table `booking`
--
ALTER TABLE `booking`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_booking_ext` (`external_source`,`external_uid`,`id`) USING BTREE,
  ADD KEY `client_id` (`customer_id`),
  ADD KEY `regle_id` (`booking_rule_id`),
  ADD KEY `canal_id` (`channel_id`),
  ADD KEY `fk_booking_property` (`property_id`);

--
-- Index pour la table `booking_guest`
--
ALTER TABLE `booking_guest`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_occ_reslogement` (`reservation_unit_id`);

--
-- Index pour la table `booking_payment`
--
ALTER TABLE `booking_payment`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_bp_booking` (`booking_id`),
  ADD KEY `idx_bp_property` (`property_id`),
  ADD KEY `idx_bp_paid_at` (`paid_at`),
  ADD KEY `idx_bp_status` (`status`);

--
-- Index pour la table `booking_rule`
--
ALTER TABLE `booking_rule`
  ADD PRIMARY KEY (`id`);

--
-- Index pour la table `booking_status`
--
ALTER TABLE `booking_status`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_resstat_reslogement` (`booking_unit_id`),
  ADD KEY `idx_resstat_statut` (`status_id`);

--
-- Index pour la table `booking_status_type`
--
ALTER TABLE `booking_status_type`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`);

--
-- Index pour la table `booking_unit`
--
ALTER TABLE `booking_unit`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `idx_bu_ext` (`external_source`,`external_uid`,`unit_id`,`id`) USING BTREE,
  ADD KEY `reservation_id` (`booking_id`),
  ADD KEY `logement_id` (`unit_id`),
  ADD KEY `idx_reslog_status_id` (`status_id`),
  ADD KEY `fk_bookingunit_property` (`property_id`);

--
-- Index pour la table `booking_unit_charge_choice`
--
ALTER TABLE `booking_unit_charge_choice`
  ADD PRIMARY KEY (`booking_unit_id`,`charge_catalog_id`),
  ADD KEY `idx_choice_charge` (`charge_catalog_id`);

--
-- Index pour la table `channel`
--
ALTER TABLE `channel`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `code` (`code`);

--
-- Index pour la table `channel_import_log`
--
ALTER TABLE `channel_import_log`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_lookup` (`channel_id`,`unit_id`,`external_uid`),
  ADD KEY `fk_importlog_unit` (`unit_id`),
  ADD KEY `fk_channelimport_property` (`property_id`);

--
-- Index pour la table `channel_mapping`
--
ALTER TABLE `channel_mapping`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_channel_key` (`channel_id`,`external_key`,`target_table`,`target_field`),
  ADD KEY `fk_channelmapping_property` (`property_id`);

--
-- Index pour la table `channel_unit`
--
ALTER TABLE `channel_unit`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_channel_unit` (`channel_id`,`unit_id`),
  ADD KEY `fk_channel_unit_unit` (`unit_id`),
  ADD KEY `fk_channelunit_property` (`property_id`);

--
-- Index pour la table `charge_booking`
--
ALTER TABLE `charge_booking`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_charges_resa_logement` (`booking_unit_id`),
  ADD KEY `idx_charge_booking_catalog` (`charge_catalog_id`);

--
-- Index pour la table `charge_catalog`
--
ALTER TABLE `charge_catalog`
  ADD PRIMARY KEY (`id`),
  ADD KEY `logement_id` (`unit_id`),
  ADD KEY `idx_charge_catalog_validity` (`property_id`,`unit_id`,`label`,`valid_from`,`valid_to`);

--
-- Index pour la table `customer`
--
ALTER TABLE `customer`
  ADD PRIMARY KEY (`id`),
  ADD KEY `fk_customer_property` (`property_id`);

--
-- Index pour la table `housekeeping_task`
--
ALTER TABLE `housekeeping_task`
  ADD PRIMARY KEY (`id`),
  ADD KEY `logement_id` (`unit_id`),
  ADD KEY `reservation_id` (`booking_id`),
  ADD KEY `fk_housekeeping_property` (`property_id`);

--
-- Index pour la table `maintenance_ticket`
--
ALTER TABLE `maintenance_ticket`
  ADD PRIMARY KEY (`id`),
  ADD KEY `logement_id` (`unit_id`),
  ADD KEY `fk_maintenance_property` (`property_id`);

--
-- Index pour la table `property`
--
ALTER TABLE `property`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `login` (`login`);
--
-- Index pour la table `rate_calendar`
--
ALTER TABLE `rate_calendar`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_ratecal` (`property_id`,`unit_id`,`channel_id`,`day`),
  ADD KEY `idx_ratecal_lookup` (`unit_id`,`day`,`channel_id`);

--
-- Index pour la table `status_transition`
--
ALTER TABLE `status_transition`
  ADD PRIMARY KEY (`from_status_id`,`to_status_id`),
  ADD KEY `to_statut_id` (`to_status_id`);

--
-- Index pour la table `stripe_event`
--
ALTER TABLE `stripe_event`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_se_event` (`stripe_event_id`),
  ADD KEY `idx_se_type` (`type`),
  ADD KEY `idx_se_account` (`stripe_account_id`);

--
-- Index pour la table `stripe_payment`
--
ALTER TABLE `stripe_payment`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uk_sp_booking_payment` (`booking_payment_id`),
  ADD UNIQUE KEY `uk_sp_pi` (`stripe_payment_intent_id`),
  ADD KEY `idx_sp_charge` (`stripe_charge_id`),
  ADD KEY `idx_sp_event` (`stripe_event_id`);

--
-- Index pour la table `unit`
--
ALTER TABLE `unit`
  ADD PRIMARY KEY (`id`),
  ADD KEY `bien_id` (`property_id`),
  ADD KEY `idx_unit_ics` (`id`,`ics_token`,`ics_enabled`);

--
-- Index pour la table `user`
--
ALTER TABLE `user`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `email` (`email`),
  ADD KEY `fk_user_property` (`property_id`);

--
-- AUTO_INCREMENT pour les tables déchargées
--

--
-- AUTO_INCREMENT pour la table `app_config`
--
ALTER TABLE `app_config`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=36;

--
-- AUTO_INCREMENT pour la table `booking`
--
ALTER TABLE `booking`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=65;

--
-- AUTO_INCREMENT pour la table `booking_guest`
--
ALTER TABLE `booking_guest`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `booking_payment`
--
ALTER TABLE `booking_payment`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT pour la table `booking_rule`
--
ALTER TABLE `booking_rule`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `booking_status`
--
ALTER TABLE `booking_status`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=33;

--
-- AUTO_INCREMENT pour la table `booking_status_type`
--
ALTER TABLE `booking_status_type`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT pour la table `booking_unit`
--
ALTER TABLE `booking_unit`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=122;

--
-- AUTO_INCREMENT pour la table `channel`
--
ALTER TABLE `channel`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT pour la table `channel_import_log`
--
ALTER TABLE `channel_import_log`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=72;

--
-- AUTO_INCREMENT pour la table `channel_mapping`
--
ALTER TABLE `channel_mapping`
  MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35;

--
-- AUTO_INCREMENT pour la table `channel_unit`
--
ALTER TABLE `channel_unit`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;

--
-- AUTO_INCREMENT pour la table `charge_booking`
--
ALTER TABLE `charge_booking`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=220;

--
-- AUTO_INCREMENT pour la table `charge_catalog`
--
ALTER TABLE `charge_catalog`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=48;

--
-- AUTO_INCREMENT pour la table `customer`
--
ALTER TABLE `customer`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=12542;

--
-- AUTO_INCREMENT pour la table `housekeeping_task`
--
ALTER TABLE `housekeeping_task`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `maintenance_ticket`
--
ALTER TABLE `maintenance_ticket`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `property`
--
ALTER TABLE `property`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `rate_calendar`
--
ALTER TABLE `rate_calendar`
  MODIFY `id` bigint UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3215;

--
-- AUTO_INCREMENT pour la table `stripe_event`
--
ALTER TABLE `stripe_event`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT pour la table `stripe_payment`
--
ALTER TABLE `stripe_payment`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT pour la table `unit`
--
ALTER TABLE `unit`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;

--
-- AUTO_INCREMENT pour la table `user`
--
ALTER TABLE `user`
  MODIFY `id` bigint NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

-- --------------------------------------------------------

--
-- Contraintes pour les tables déchargées
--

--
-- Contraintes pour la table `app_config`
--
ALTER TABLE `app_config`
  ADD CONSTRAINT `fk_appcfg_prop` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_appcfg_unit` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `booking`
--
ALTER TABLE `booking`
  ADD CONSTRAINT `booking_ibfk_1` FOREIGN KEY (`customer_id`) REFERENCES `customer` (`id`),
  ADD CONSTRAINT `booking_ibfk_3` FOREIGN KEY (`booking_rule_id`) REFERENCES `booking_rule` (`id`),
  ADD CONSTRAINT `fk_booking_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`);

--
-- Contraintes pour la table `booking_guest`
--
ALTER TABLE `booking_guest`
  ADD CONSTRAINT `fk_occ_reslogement` FOREIGN KEY (`reservation_unit_id`) REFERENCES `booking_unit` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `booking_payment`
--
ALTER TABLE `booking_payment`
  ADD CONSTRAINT `fk_bp_booking` FOREIGN KEY (`booking_id`) REFERENCES `booking` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_bp_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `booking_status`
--
ALTER TABLE `booking_status`
  ADD CONSTRAINT `fk_resstat_reslogement` FOREIGN KEY (`booking_unit_id`) REFERENCES `booking_unit` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_resstat_stat` FOREIGN KEY (`status_id`) REFERENCES `booking_status_type` (`id`);

--
-- Contraintes pour la table `booking_unit`
--
ALTER TABLE `booking_unit`
  ADD CONSTRAINT `booking_unit_ibfk_1` FOREIGN KEY (`booking_id`) REFERENCES `booking` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `booking_unit_ibfk_2` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_bookingunit_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
  ADD CONSTRAINT `fk_reslog_statut` FOREIGN KEY (`status_id`) REFERENCES `booking_status_type` (`id`);

--
-- Contraintes pour la table `channel_import_log`
--
ALTER TABLE `channel_import_log`
  ADD CONSTRAINT `fk_channelimport_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
  ADD CONSTRAINT `fk_importlog_channel` FOREIGN KEY (`channel_id`) REFERENCES `channel` (`id`),
  ADD CONSTRAINT `fk_importlog_unit` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`);

--
-- Contraintes pour la table `channel_mapping`
--
ALTER TABLE `channel_mapping`
  ADD CONSTRAINT `fk_channel_mapping_channel` FOREIGN KEY (`channel_id`) REFERENCES `channel` (`id`);

--
-- Contraintes pour la table `channel_unit`
--
ALTER TABLE `channel_unit`
  ADD CONSTRAINT `fk_channel_unit_channel` FOREIGN KEY (`channel_id`) REFERENCES `channel` (`id`),
  ADD CONSTRAINT `fk_channel_unit_unit` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`),
  ADD CONSTRAINT `fk_channelunit_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`);

--
-- Contraintes pour la table `charge_booking`
--
ALTER TABLE `charge_booking`
  ADD CONSTRAINT `fk_charges_resa_logement` FOREIGN KEY (`booking_unit_id`) REFERENCES `booking_unit` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `charge_catalog`
--
ALTER TABLE `charge_catalog`
  ADD CONSTRAINT `charge_catalog_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`),
  ADD CONSTRAINT `fk_chargecatalog_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`);

--
-- Contraintes pour la table `customer`
--
ALTER TABLE `customer`
  ADD CONSTRAINT `fk_customer_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`);

--
-- Contraintes pour la table `housekeeping_task`
--
ALTER TABLE `housekeeping_task`
  ADD CONSTRAINT `fk_housekeeping_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
  ADD CONSTRAINT `housekeeping_task_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`),
  ADD CONSTRAINT `housekeeping_task_ibfk_2` FOREIGN KEY (`booking_id`) REFERENCES `booking` (`id`);

--
-- Contraintes pour la table `maintenance_ticket`
--
ALTER TABLE `maintenance_ticket`
  ADD CONSTRAINT `fk_maintenance_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`),
  ADD CONSTRAINT `maintenance_ticket_ibfk_1` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`);

--
-- Contraintes pour la table `rate_calendar`
--
ALTER TABLE `rate_calendar`
  ADD CONSTRAINT `fk_ratecal_prop` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `fk_ratecal_unit` FOREIGN KEY (`unit_id`) REFERENCES `unit` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `status_transition`
--
ALTER TABLE `status_transition`
  ADD CONSTRAINT `status_transition_ibfk_1` FOREIGN KEY (`from_status_id`) REFERENCES `booking_status_type` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `status_transition_ibfk_2` FOREIGN KEY (`to_status_id`) REFERENCES `booking_status_type` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `stripe_payment`
--
ALTER TABLE `stripe_payment`
  ADD CONSTRAINT `fk_sp_booking_payment` FOREIGN KEY (`booking_payment_id`) REFERENCES `booking_payment` (`id`) ON DELETE CASCADE;

--
-- Contraintes pour la table `unit`
--
ALTER TABLE `unit`
  ADD CONSTRAINT `unit_ibfk_1` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`);

--
-- Contraintes pour la table `user`
--
ALTER TABLE `user`
  ADD CONSTRAINT `fk_user_property` FOREIGN KEY (`property_id`) REFERENCES `property` (`id`) ON DELETE CASCADE;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
