$table_info) { if ($this->is_excluded_table($table_name)) { continue; } // Check each column for session_id foreach ($table_info['columns'] as $column) { if ($column['name'] === 'session_id') { // Check if nullable if ($column['nullable'] !== 'YES') { $this->add_violation( $table_name, 'session_id', 'Column session_id must be nullable', 'ALTER TABLE ' . $table_name . ' MODIFY session_id VARCHAR(255) NULL' ); } // Check for foreign key $has_proper_fk = false; foreach ($table_info['foreign_keys'] as $fk) { if ($fk['column'] === 'session_id' && $fk['referenced_table'] === 'sessions' && $fk['referenced_column'] === 'id' && $fk['delete_rule'] === 'CASCADE') { $has_proper_fk = true; break; } } if (!$has_proper_fk) { $this->add_violation( $table_name, 'session_id', 'Column session_id must have foreign key to sessions.id with ON DELETE CASCADE', 'ALTER TABLE ' . $table_name . ' ADD CONSTRAINT fk_' . $table_name . '_session ' . 'FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE' ); } } } } } }