Skip to content

Data Migration

Guide for migrating analytics data between versions and from other analytics systems.

Migration Scenarios

Upgrading from Visitors 2.x to 3.x

The module provides automated migration paths for existing installations.

Database Schema Updates

  • Automatic schema updates via update hooks
  • Data preservation during upgrades
  • New field additions with default values

Migration Process

# Backup existing data
drush sql:dump --result-file=visitors_backup.sql

# Run updates
drush updatedb

# Run Visitors upgrade (if migrating from 2.x)
drush visitors:upgrade

Available Drush Commands

The Visitors module provides the following drush commands:

drush visitors:upgrade

Purpose: Upgrade data from Visitors 8.x-2.x to 3.0.x Usage: drush visitors:upgrade Alias: drush visitors-upgrade

This command migrates existing visitor data to the new schema format and should be run after upgrading from older versions.

Command Output

The upgrade command provides: - Progress bar showing migration status - Real-time feedback on records processed - Completion confirmation when finished

Statistics node counts

Core Statistics stores aggregate node counts in node_counter (nid, totalcount, daycount, timestamp). It does not store each hit, so this migration fills visitors_counter and does not create visit or event rows.

Enable Migrate, and Migrate Tools if you import with Drush. Point a database connection named migrate at the Drupal 8 database. Visitors reads that connection by default. See Migrating data from a SQL source.

When the rebuilt nodes keep their IDs, import after the node migrations:

drush migrate:import visitors_statistics_node_counter

When node IDs change, name the node migrations in hook_migration_plugins_alter():

function my_module_migration_plugins_alter(array &$migrations) {
  if (!isset($migrations['visitors_statistics_node_counter'])) {
    return;
  }
  $migrations['visitors_statistics_node_counter']['source']['node_migrations'] = [
    'my_node_migration',
  ];
}

A node that was not migrated is skipped. A second import with drush migrate:import visitors_statistics_node_counter --update replaces the counts for migrated nodes. Import before the new site records its own views. drush migrate:rollback visitors_statistics_node_counter deletes only the rows this migration wrote.

daycount is copied to today. Visitors cron sets every today value back to 0 after a day.

If Statistics is installed on the same site, the form at Administration, Configuration, System, Visitors, Statistics copies node_counter and uninstalls Statistics. Use the migration above when the old table is on another database.

Custom Migration Scripts

For complex migrations or custom analytics systems, you can create custom migration scripts.

Data Integrity

Validation Checks

  • Data consistency verification
  • Foreign key constraint validation
  • Statistical accuracy checks

Rollback Procedures

  • Database restoration from backups
  • Selective data rollback options
  • Migration status tracking

For technical migration details, see Database Tables.