DROP TABLE wbsv2_from_napi.SAS_ADDRESS;
DROP TABLE wbsv2_from_napi.SAS_SDA;
DROP TABLE wbsv2_from_napi.SAS_SITE;
DROP TABLE wbsv2_from_napi.SAS_CUSTOMER;
DROP TABLE wbsv2_from_napi.SAS_PARTNER;


CREATE TABLE wbsv2_from_napi.SAS_PARTNER (
                                             id bigint NOT NULL,
                                             type varchar(255) NULL DEFAULT 'revendeur',
                                             name varchar(255) NULL,
                                             created_at datetime NULL,
                                             updated_at_by_selfcare datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                             updated_at_by_wbs datetime NULL,
                                             deleted_at datetime NULL,
                                             is_active varchar(1)  NULL,
                                             to_imported_to_wbs varchar(1)  NULL,
                                             exported_by_selfcare_at datetime  NULL DEFAULT CURRENT_TIMESTAMP,
                                             imported_by_wbs_at datetime NULL,
                                             key_selfcare varchar(255) NULL,
                                             key_selfcare_v1 varchar(255) NULL,
                                             key_wbs varchar(255) NULL,
                                             to_exported_to_selfcare varchar(1) NULL,
                                             CONSTRAINT SAS_PARTER_PK PRIMARY KEY (id)
);




CREATE TABLE wbsv2_from_napi.SAS_CUSTOMER (
                                              id bigint NOT NULL,
                                              id_partner bigint NULL,
                                              name varchar(255) NULL,
                                              id_default_site bigint NULL,
                                              created_at datetime NULL,
                                              updated_at_by_selfcare datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                              updated_at_by_wbs datetime NULL,
                                              deleted_at datetime NULL,
                                              is_active varchar(1) NULL,
                                              to_imported_to_wbs varchar(1) NULL,
                                              exported_by_selfcare_at datetime  NULL DEFAULT CURRENT_TIMESTAMP,
                                              imported_by_wbs_at datetime NULL,
                                              key_selfcare varchar(255) NULL,
                                              key_selfcare_v1 varchar(255) NULL,
                                              key_wbs varchar(255) NULL,
                                              to_exported_to_selfcare varchar(1) NULL,
                                              CONSTRAINT SAS_CUSTOMER_PK PRIMARY KEY (id)
);

ALTER TABLE wbsv2_from_napi.SAS_CUSTOMER ADD CONSTRAINT SAS_CUSTOMER_SAS_PARTNER_FK FOREIGN KEY (id_partner) REFERENCES wbsv2_from_napi.SAS_PARTNER(id);




CREATE TABLE wbsv2_from_napi.SAS_SITE (
                                          id bigint NOT NULL,
                                          id_customer bigint NULL,
                                          name varchar(255) NULL,
                                          created_at datetime NULL,
                                          updated_at_by_selfcare datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                          updated_at_by_wbs datetime NULL,
                                          deleted_at datetime NULL,
                                          is_active varchar(1) NULL,
                                          to_imported_to_wbs varchar(1) NULL,
                                          exported_by_selfcare_at datetime  NULL DEFAULT CURRENT_TIMESTAMP,
                                          imported_by_wbs_at datetime NULL,
                                          key_selfcare varchar(255) NULL,
                                          key_selfcare_v1 varchar(255) NULL,
                                          key_wbs varchar(255) NULL,
                                          to_exported_to_selfcare varchar(1) NULL,
                                          CONSTRAINT SAS_SITE_PK PRIMARY KEY (id)
);

ALTER TABLE wbsv2_from_napi.SAS_SITE ADD CONSTRAINT SAS_SITE_ISE_CUSTOMER_FK FOREIGN KEY (id_customer) REFERENCES wbsv2_from_napi.SAS_CUSTOMER(id);



CREATE TABLE wbsv2_from_napi.SAS_SDA (
                                         id bigint NOT NULL,
                                         id_site bigint NULL,
                                         long_number varchar(255) NULL,
                                         short_number varchar(255) NULL,
                                         created_at datetime NULL,
                                         updated_at_by_selfcare datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                         updated_at_by_wbs datetime NULL,
                                         deleted_at datetime NULL,
                                         product varchar(255) NULL DEFAULT 'voip',
                                         is_active varchar(1) NULL,
                                         to_imported_to_wbs varchar(1) NULL DEFAULT 1,
                                         exported_by_selfcare_at datetime  NULL DEFAULT CURRENT_TIMESTAMP,
                                         imported_by_wbs_at datetime NULL,
                                         key_selfcare varchar(255) NULL,
                                         key_selfcare_v1 varchar(255) NULL,
                                         key_wbs varchar(255) NULL,
                                         to_exported_to_selfcare varchar(1) NULL,
                                         CONSTRAINT SAS_SDA_PK PRIMARY KEY (id)
);

ALTER TABLE wbsv2_from_napi.SAS_SDA ADD CONSTRAINT SAS_SDA_ISE_SITE_FK FOREIGN KEY (id_site) REFERENCES wbsv2_from_napi.SAS_SITE(id);

CREATE TABLE wbsv2_from_napi.SAS_ADDRESS (
                                             id bigint NOT NULL,
                                             id_partner bigint NULL,
                                             id_customer bigint NULL,
                                             id_site bigint NULL,
                                             siret varchar(255) NULL,
                                             street varchar(255) NULL,
                                             postal_code varchar(255) NULL,
                                             city varchar(255) NULL,
                                             country varchar(255) NULL,
                                             comment varchar(255) NULL,
                                             created_at datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                             deleted_at datetime NULL,
                                             is_active varchar(1) NULL,
                                             to_imported_to_wbs varchar(1) NULL,
                                             exported_by_selfcare_at datetime NULL DEFAULT CURRENT_TIMESTAMP,
                                             imported_by_wbs_at datetime NULL,
                                             key_selfcare varchar(255) NULL,
                                             key_selfcare_v1 varchar(255) NULL,
                                             key_wbs varchar(255) NULL,
                                             to_exported_to_selfcare varchar(1) NULL,
                                             CONSTRAINT SAS_ADDRESS_PK PRIMARY KEY (id)
);



ALTER TABLE wbsv2_from_napi.SAS_ADDRESS ADD CONSTRAINT SAS_ADDRESS_SAS_PARTNER_FK FOREIGN KEY (id_partner) REFERENCES wbsv2_from_napi.SAS_PARTNER(id);
ALTER TABLE wbsv2_from_napi.SAS_ADDRESS ADD CONSTRAINT SAS_ADDRESS_SAS_CUSTOMER_FK FOREIGN KEY (id_customer) REFERENCES wbsv2_from_napi.SAS_CUSTOMER(id);
ALTER TABLE wbsv2_from_napi.SAS_ADDRESS ADD CONSTRAINT SAS_ADDRESS_SAS_SITE_FK FOREIGN KEY (id_site) REFERENCES wbsv2_from_napi.SAS_SITE(id);


CREATE TABLE wbsv2_from_napi.SAS_USER (
                            `id` int NOT NULL,
                            `username` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

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

--
-- Index pour la table `SAS_USER`
--
ALTER TABLE wbsv2_from_napi.SAS_USER
    ADD PRIMARY KEY (`id`);

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

--
-- AUTO_INCREMENT pour la table `SAS_USER`
--
ALTER TABLE wbsv2_from_napi.SAS_USER
    MODIFY `id` int NOT NULL AUTO_INCREMENT;
COMMIT;


