createTable('stat_hit'); $hits->addColumn('id', 'integer', ['autoincrement' => true]); $hits->addColumn('website_id', 'string', ['length' => 64]); $hits->addColumn('day', 'string', ['length' => 10]); // 0 to 23, or -1 for a day that has been compacted from hours into one row. $hits->addColumn('hour', 'smallint'); $hits->addColumn('path', 'string', ['length' => 200]); $hits->addColumn('status', 'smallint'); // Empty for a direct visit or a link from this site itself; a bare host otherwise. $hits->addColumn('referrer_host', 'string', ['length' => 100, 'default' => '']); $hits->addColumn('count', 'integer', ['default' => 0]); $hits->setPrimaryKey(['id']); // The counter is found by this tuple, so it has to be unique - otherwise two requests in // the same second would create two rows instead of incrementing one. $hits->addUniqueIndex(['website_id', 'day', 'hour', 'path', 'status', 'referrer_host'], 'uniq_stat_hit'); $hits->addIndex(['website_id', 'day'], 'idx_stat_hit_day'); } public function down(Schema $schema): void { // Dropping it loses the measurement and nothing else: no content, no account, no media. $schema->dropTable('stat_hit'); } }