definition:
  user: >
    SELECT ROW_NUMBER() OVER (ORDER BY clientes.user.id) AS id,
           email,
           IF(JSON_SEARCH(roles, 'one', 'ROLE_REPRESENTANTE') IS NULL, IF(roles = '[]', '["ROLE_CLIENTE"]', roles),
              '["ROLE_CLIENTE", "ROLE_REPRESENTANTE"]') as roles,
           password,
           name,
           lastname,
           is_verified,
           active,
           wizard_shown,
           codigo,
           created_at,
           updated_at
    from clientes.user
    ORDER BY clientes.user.id

  direccion: >
    select null, centro_poblado_id, null, direccion, codigo_postal, null
    from clientes.direccion

  cliente: >
    select ROW_NUMBER() OVER (ORDER BY clientes.cliente.id) as id, direccion_establecimiento_comercial_id, venta_tipo_id,
           vendedor_id, identificacion_tipo_id, direccion_id, verified,
           nuevo, she, segundo_nombre, primer_apellido, segundo_apellido, nombre_comercial, identificacion_verificacion,
           registro_mercantil, celular, whatsapp, venta_ebooks, web, numero_sucursales, constitucion_tipo, nombre_principal,
           identificacion, telefono, email, origen_fondos, acepto_terminos_en, created_at, updated_at
    from clientes.cliente ORDER BY clientes.cliente.id

  cliente_user: >
    select cc.position as cliente_id, cu.position as user_id
    from clientes.cliente_user ccu
    join (
    SELECT ROW_NUMBER() OVER (ORDER BY cc.id) AS position, cc.id
    FROM clientes.cliente cc
    ORDER BY cc.id)cc on ccu.cliente_id = cc.id
    join (
    SELECT ROW_NUMBER() OVER (ORDER BY u.id) AS position, u.id
    FROM clientes.user u
    ORDER BY u.id)cu on ccu.user_id = cu.id

  sucursal: >
    SELECT ROW_NUMBER() OVER (ORDER BY s.id) as id, c.position as cliente_id, s.direccion_id, s.nombre, s.she
    FROM clientes.sucursal s
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on s.cliente_id = c.id
    ORDER BY s.id

  regimen_tributario: >
    select ROW_NUMBER() OVER (ORDER BY rt.id) AS id, c.position as cliente_id, null as proveedor_id, rt.regimen_tipo_id,
    rt.iva_ciiu_id, rt.ica_ciiu_id, rt.sociedad_tipo_id, rt.resolucion_numero, rt.responsable_iva, rt.ica,
    rt.fecha_inscripcion, rt.retefuente, rt.sociedad_tipo_otro_detalle, null as naturaleza,
    null as gran_contribuyente, null as auto_retenedor, null as decalara_renta, null as ica_numero
    from clientes.regimen_tributario rt
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on rt.cliente_id = c.id
    ORDER BY rt.id

  representante_legal: >
    select ROW_NUMBER() OVER (ORDER BY rl.id) as id, c.position as cliente_id, rl.identificacion_tipo_id, rl.primer_nombre,
    rl.segundo_nombre, rl.primer_apellido, rl.segundo_apellido, rl.identificacion, rl.identificacion_fecha_expedicion, rl.telefono,
    rl.celular, rl.email
    from clientes.representante_legal rl
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on rl.cliente_id = c.id
    ORDER BY rl.id

  contacto: >
    SELECT ROW_NUMBER() OVER (ORDER BY co.id) AS id, c.position as cliente_id, null as proveedor_id, co.contacto_tipo_id,
    co.nombres, co.apellidos, co.email, co.telefono, null as celular, co.boletines, null as cargo
    FROM clientes.contacto co
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on co.cliente_id = c.id
    ORDER BY co.id

  documento: >
    SELECT ROW_NUMBER() OVER (ORDER BY d.id) AS id, c.position as cliente_id, null as proveedor_id, d.documento_tipo_id,
    d.filename, d.original_filename, d.mime_type, d.size, d.extension, d.is_image
    FROM clientes.documento d
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on d.cliente_id = c.id
    ORDER BY d.id

  solicitud: >
    select ROW_NUMBER() over (ORDER BY s.id) as id, c.position as cliente_id, null as proveedor_id, s.porcentaje, s.estado,
    s.created_at, s.updated_at
    from clientes.solicitud s
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on s.cliente_id = c.id
    ORDER BY s.id

  solicitud_paso: >
    SELECT ROW_NUMBER() OVER (ORDER BY sp.id) as id, s.position as solicitud_id, sp.identificador, sp.ok, sp.ok_verificar,
    sp.created_constitucion_tipo as created_tipo, sp.created_at, sp.updated_at
    FROM clientes.solicitud_paso sp
    join (SELECT ROW_NUMBER() OVER (ORDER BY s.id) AS position, s.id FROM clientes.solicitud s ORDER BY s.id)s on sp.solicitud_id = s.id
    ORDER BY sp.id

  solicitud_cliente: >
    select ROW_NUMBER() OVER (ORDER BY sc.id) AS id, c.position as cliente_id,  s.position as solicitud_id,
    direccion_establecimiento_comercial_id, venta_tipo_id, vendedor_id, identificacion_tipo_id, direccion_id, she,
    segundo_nombre, primer_apellido, segundo_apellido, nombre_comercial, identificacion_verificacion, registro_mercantil,
    celular, whatsapp, venta_ebooks, web, numero_sucursales, constitucion_tipo, nombre_principal, identificacion,
    telefono, email, origen_fondos, acepto_terminos_en
    from clientes.solicitud_cliente sc
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.cliente c ORDER BY c.id)c on sc.cliente_id = c.id
    join (SELECT ROW_NUMBER() OVER (ORDER BY s.id) AS position, s.id FROM clientes.solicitud s ORDER BY s.id)s on sc.solicitud_id = s.id
    ORDER BY sc.id

  solicitud_sucursal: >
    SELECT ROW_NUMBER() OVER (ORDER BY s.id) as id, c.position as cliente_id, s.direccion_id, s.nombre, s.she
    FROM clientes.solicitud_sucursal s
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.solicitud_cliente c ORDER BY c.id)c on s.cliente_id = c.id
    ORDER BY s.id

  solicitud_regimen_tributario: >
    SELECT ROW_NUMBER() OVER (ORDER BY srt.id) as id, c.position as cliente_id, null as proveedor_id, srt.regimen_tipo_id,
    srt.iva_ciiu_id, srt.ica_ciiu_id, srt.sociedad_tipo_id, srt.resolucion_numero, srt.responsable_iva,
    srt.ica, srt.fecha_inscripcion, srt.retefuente, srt.sociedad_tipo_otro_detalle, null as naturaleza,
    null as gran_contribuyente, null as auto_retenedor, null as declara_renta, null as ica_numero
    FROM clientes.solicitud_regimen_tributario srt
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.solicitud_cliente c ORDER BY c.id)c on srt.cliente_id = c.id
    ORDER BY srt.id

  solicitud_representante_legal: >
    SELECT ROW_NUMBER() OVER (ORDER BY srl.id) as id, c.position as cliente_id, srl.identificacion_tipo_id, srl.primer_nombre,
    srl.segundo_nombre, srl.primer_apellido, srl.segundo_apellido, srl.identificacion, srl.identificacion_fecha_expedicion,
    srl.telefono, srl.celular, srl.email
    FROM clientes.solicitud_representante_legal srl
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.solicitud_cliente c ORDER BY c.id)c on srl.cliente_id = c.id
    ORDER BY srl.id

  solicitud_contacto: >
    SELECT ROW_NUMBER() OVER (ORDER BY sc.id) as id, c.position as cliente_id, null as proveedor_id,
    sc.nombres, sc.email, sc.telefono, null as celular, sc.boletines, null as cargo, sc.contacto_tipo_id, sc.apellidos
    FROM clientes.solicitud_contacto sc
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.solicitud_cliente c ORDER BY c.id)c on sc.cliente_id = c.id
    ORDER BY sc.id

  solicitud_documento: >
    SELECT ROW_NUMBER() OVER (ORDER BY sd.id) as id, c.position as cliente_id, null as proveedor_id,
    sd.documento_tipo_id, sd.filename, sd.original_filename, sd.mime_type, sd.size, sd.extension, sd.is_image
    FROM clientes.solicitud_documento sd
    join (SELECT ROW_NUMBER() OVER (ORDER BY c.id) AS position, c.id FROM clientes.solicitud_cliente c ORDER BY c.id)c on sd.cliente_id = c.id
    ORDER BY sd.id

  solicitud_nota: >
    SELECT ROW_NUMBER() OVER (ORDER BY sn.id) as id, s.position as solicitud_id, sn.paso, sn.campo, sn.texto, sn.resolved
    FROM clientes.solicitud_nota sn
    join (SELECT ROW_NUMBER() OVER (ORDER BY s.id) AS position, s.id FROM clientes.solicitud s ORDER BY s.id)s on sn.solicitud_id = s.id
    ORDER BY sn.id