CREATE TYPE status_enum AS ENUM ('noRequestID','noMassID','running','finished','error','other'); -- Tabla para gestionar las peticiones de cambio de objenious. -- Para una o mas lineas se pueden lanzar operacione que no sabemos -- con certeza cuando van a terminar. CREATE TABLE if not exists objenious_operation ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, retry_count INT DEFAULT 0, max_retry INT DEFAULT 5, max_date_retry TIMESTAMP DEFAULT NULL, iccids TEXT, request_id TEXT, mass_action_id TEXT, operation TEXT NOT NULL, start_date TIMESTAMP NOT NULL DEFAULT now(), last_change_date TIMESTAMP NOT NULL DEFAULT now(), end_date TIMESTAMP, error TEXT, status status_enum ); -- operaciones pendientes para revisar CREATE INDEX IF NOT EXISTS pending_operations ON objenious_operation(start_date) WHERE end_date IS NULL; CREATE TABLE if not exists objenious_operation_change ( id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY, operation_id BIGINT, creation_date TIMESTAMP NOT NULL DEFAULT now(), error TEXT, new_status status_enum, new_request_id TEXT, new_mass_action_id TEXT, CONSTRAINT fk_operation_id FOREIGN KEY(operation_id) REFERENCES objenious_operation(id) ); CREATE INDEX operation_change ON objenious_operation_change(operation_id);