protected function augmentSQLVersionedArchive(SQLSelect $query, DataQuery $dataQuery)
    {
        $baseTable = $this->baseTable();
        $date = $dataQuery->getQueryParam('Versioned.date');
        if (!$date) {
            throw new InvalidArgumentException("Invalid archive date");
        }

        // Query against _Versions table first
        $this->augmentSQLVersioned($query);

        // Validate stage
        $stage = $dataQuery->getQueryParam('Versioned.stage');
        ReadingMode::validateStage($stage);

        // Filter on appropriate stage column in addition to date
        if ($this->hasStages()) {
            $stageColumn = $stage === static::LIVE
                ? 'WasPublished'
                : 'WasDraft';
            $stageCondition = "AND \"{$baseTable}_Versions\".\"{$stageColumn}\" = 1";
        } else {
            $stageCondition = '';
        }

        // Join on latest version filtered by date
        $query->addInnerJoin(
            <<<SQL
            (
            SELECT "{$baseTable}_Versions"."RecordID",
                MAX("{$baseTable}_Versions"."Version") AS "LatestVersion"
            FROM "{$baseTable}_Versions"
            WHERE "{$baseTable}_Versions"."LastEdited" <= ?
                {$stageCondition}
            GROUP BY "{$baseTable}_Versions"."RecordID"
            )
SQL
            ,
            <<<SQL
            "{$baseTable}_Versions_Latest"."RecordID" = "{$baseTable}_Versions"."RecordID"
            AND "{$baseTable}_Versions_Latest"."LatestVersion" = "{$baseTable}_Versions"."Version"
SQL
            ,
            "{$baseTable}_Versions_Latest",
            20,
            [$date]
        );
    }