-- Copyright (C) 2025 Eric Seigne <eric.seigne@cap-rel.fr>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see https://www.gnu.org/licenses/.

ALTER TABLE llx_facturx_apimport ADD INDEX idx_facturx_apimport_ref (ref);
ALTER TABLE llx_facturx_apimport ADD INDEX idx_facturx_apimport_status (status);
ALTER TABLE llx_facturx_apimport ADD INDEX idx_facturx_apimport_entity (entity);
-- Uniqueness is entity-aware: the access point document id and the module
-- reference can live in two entities, and the (ref, entity) constraint is
-- what closes the numbering race of getNextValue() on concurrent imports.
ALTER TABLE llx_facturx_apimport ADD UNIQUE INDEX uk_facturx_apimport_facturxid (facturxid, entity);
ALTER TABLE llx_facturx_apimport ADD UNIQUE INDEX uk_facturx_apimport_ref (ref, entity);
ALTER TABLE llx_facturx_apimport ADD CONSTRAINT llx_facturx_apimport_fk_user_creat FOREIGN KEY (fk_user_creat) REFERENCES llx_user(rowid);
