# Production schema and view definition

The production audit established these exact entity tables:

    CREATE TABLE vtiger_marvelpbx (
      marvelpbxid int(19) NOT NULL,
      PRIMARY KEY (marvelpbxid)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

    CREATE TABLE vtiger_marvelpbxcf (
      marvelpbxid int(19) NOT NULL,
      PRIMARY KEY (marvelpbxid)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;

The exact audited reporting SELECT, also used by the lifecycle handler, is:

    CREATE VIEW vtiger_marvelpbx_view AS
    SELECT
        p.pbxmanagerid,
        p.direction,
        p.callstatus,
        p.starttime,
        p.endtime,
        p.totalduration,
        p.billduration,
        p.recordingurl,
        p.sourceuuid,
        p.gateway,
        p.customer AS customer_raw,
        p.user AS user_raw,
        p.customernumber,
        p.customertype,
        ce.deleted,
        ce.createdtime AS crm_createdtime,
        ce.modifiedtime AS crm_modifiedtime,
        ce.label,
        ce.smownerid,
        u.id AS vt_user_id,
        u.user_name,
        u.first_name,
        u.last_name,
        u.phone_crm_extension,
        cd.contactid,
        cd.firstname AS contact_firstname,
        cd.lastname AS contact_lastname,
        cd.mobile AS contact_mobile,
        cd.phone AS contact_phone,
        cd.accountid,
        acc.accountname
    FROM vtiger_pbxmanager p
    INNER JOIN vtiger_crmentity ce
        ON ce.crmid = p.pbxmanagerid
       AND ce.setype = 'PBXManager'
    LEFT JOIN vtiger_users u
        ON u.id = CAST(p.user AS UNSIGNED)
    LEFT JOIN vtiger_contactdetails cd
        ON cd.contactid = CAST(p.customer AS UNSIGNED)
    LEFT JOIN vtiger_account acc
        ON acc.accountid = cd.accountid;

Production reported ALGORITHM=UNDEFINED, SQL SECURITY DEFINER, and an environment-local root@localhost definer. The package intentionally omits that non-portable definer while preserving the exact column set, aliases, predicate, and joins. The view is read-only integration metadata; no PBXManager or crmentity data is copied or changed.

## VTiger 8.4 placement constraints

The audited vtiger_parenttab table has PRIMARY KEY(parenttabid). vtiger_parenttabrel has foreign keys for tabid and parenttabid plus non-unique indexes, but no primary or unique constraint across parenttabid/tabid. vtiger_app2tab has a foreign key on tabid and a non-unique index, but no primary or unique constraint across tabid/appname. Duplicate placement rows are therefore structurally possible and must be normalized in lifecycle code without touching unrelated rows.
